summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/codeq/hint.js52
1 files changed, 44 insertions, 8 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js
index 6f54717..a97c14b 100644
--- a/js/codeq/hint.js
+++ b/js/codeq/hint.js
@@ -236,14 +236,42 @@
'popup': function (type, template, serverHint) {
codeq.log.debug('Processing popup hint');
- var message = processTemplate(template, serverHint.args),
+ var args = serverHint.args,
mark = addMark(serverHint.start, serverHint.end), // add the mark
- jqMark = jqEditor.find('.' + mark.className);
+ langs = codeq.availableLangs,
+ translations = {},
+ lang, i, content, htmlPrefix;
- jqMark.popover({'content': message, 'html': true, 'placement': 'auto bottom', 'trigger': 'hover focus click', 'container': 'body'});
- hintCleaners.push(function () { if (jqMark) { jqMark.popover('destroy'); jqMark = null; } });
-
- mark.mark.on('', function () {});
+ // execute templates for all languages
+ for (i = langs.length - 1; i >= 0; i--) {
+ lang = langs[i];
+ content = template[lang];
+ if (typeof content === 'string') {
+ translations[lang] = processTemplate(content, args);
+ }
+ else {
+ translations[lang] = 'No translation in ' + lang + ' available for ' + type + ' hint ' + serverHint.id;
+ codeq.log.error(translations[lang]);
+ }
+ }
+ // construct the wrapper element for the translation mechanism
+ htmlPrefix = '<span ' + ta(translations) + '>';
+ // create the popover after all the DOM modifications have been made, otherwise only the last made popover can be triggered
+ return function () {
+ var jqMark = jqEditor.find('.' + mark.className);
+ jqMark.popover({
+ 'content': function () {
+ // decide on what to display only after the popup is triggered, so we can choose the correct translation
+ return htmlPrefix + translations[codeq.getLang()] + '</span>';
+ },
+ 'html': true,
+ 'placement': 'auto bottom',
+ 'trigger': 'hover focus click',
+ 'container': 'body'
+ });
+ // remove the popup on next hint pack
+ hintCleaners.push(function () { if (jqMark) { jqMark.popover('destroy'); jqMark = null; } });
+ };
},
'dropdown': function (type, template, serverHint) {
@@ -312,7 +340,8 @@
*/
'handle': function (serverHints) {
var n = serverHints.length,
- i, serverHint, hintId, hintDef, hintContent, hintType, t, fn, indices;
+ finalizers = [],
+ i, serverHint, hintId, hintDef, hintContent, hintType, t, fn, ret;
clearHints();
mainLoop:
@@ -346,7 +375,14 @@
fn = typeHandlers[hintType];
if (!fn) codeq.log.error('Unsupported hint type: ' + hintType);
- else fn(hintType, hintContent, serverHint, hintId);
+ else {
+ ret = fn(hintType, hintContent, serverHint, hintId);
+ if (typeof ret === 'function') finalizers.push(ret);
+ }
+ }
+ // invoke any finalizers
+ for (i = 0; i < finalizers.length; i++) {
+ finalizers[i]();
}
},