summaryrefslogtreecommitdiff
path: root/js/codeq/core.js
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-09-30 17:37:31 +0200
committerAleš Smodiš <aless@guru.si>2015-09-30 17:37:31 +0200
commit0da1117cfc28688633be7b8382aa60435bf740eb (patch)
treeb464b92e673419db595c231ed1ba8e7c6cfd783b /js/codeq/core.js
parent8995341d43efe16f307b55f200821944cfecf4c8 (diff)
Implemented GUI translations via the data-tkey tag attribute and res/*.json files.
Diffstat (limited to 'js/codeq/core.js')
-rw-r--r--js/codeq/core.js63
1 files changed, 56 insertions, 7 deletions
diff --git a/js/codeq/core.js b/js/codeq/core.js
index 01382d1..29b497c 100644
--- a/js/codeq/core.js
+++ b/js/codeq/core.js
@@ -372,6 +372,49 @@
// The boot sequence
// ================================================================================
+ var loadGuiTranslations = function () {
+ var langs = codeq.availableLangs,
+ loaders = [],
+ loaderLangs = [],
+ i, lang;
+ for (i = langs.length - 1; i >= 0; i--) {
+ lang = langs[i];
+ loaders.push(codeq.comms.getGuiTranslation(lang));
+ loaderLangs.push(lang);
+ }
+ return Q.all(loaders)
+ .then(function (results) {
+ // convert translations into something that the translation module can use
+ var dictionary = {},
+ i, json, key, lang, translations;
+ for (i = results.length - 1; i >= 0; i--) {
+ json = results[i];
+ lang = loaderLangs[i];
+ for (key in json) {
+ if (!json.hasOwnProperty(key)) continue;
+ translations = dictionary[key];
+ if (translations) translations[lang] = json[key];
+ else {
+ translations = {};
+ dictionary[key] = translations;
+ translations[lang] = json[key];
+ }
+ }
+ }
+ // ensure each key contains all translations
+ for (key in dictionary) {
+ if (!dictionary.hasOwnProperty(key)) continue;
+ translations = dictionary[key];
+ for (i = langs.length - 1; i >= 0; i--) {
+ lang = langs[i];
+ if (!(lang in translations)) translations[lang] = "(Untranslated: " + lang + ")";
+ }
+ }
+ // register with the system
+ codeq.tr.registerDictionary('gui', dictionary);
+ });
+ };
+
$(document).ready(function () {
// set the language
var navigatorLang = navigator.language || navigator.browserLanguage, // language reported by browser
@@ -387,11 +430,17 @@
codeq.availableLangs.push(key);
}
- codeq.fire('init'); // tell any interested modules that we are not initialized, perhaps they want to initialize too
- codeq.setLang(lang || 'en'); // initial language setting
- // go to login
- codeq.globalStateMachine.transition('login');
-
- //For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning you must initialize them yourself.
- $('[data-toggle="popover"]').popover()});
+ // the boot chain: must be a sequence of .then() terminated with .done()
+ loadGuiTranslations()
+ .then(function () {
+ codeq.fire('init'); // tell any interested modules that we are now initialized, perhaps they want to initialize too
+ codeq.setLang(lang || 'en'); // initial language setting, this also translates the GUI
+ // go to login
+ codeq.globalStateMachine.transition('login');
+
+ //For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning you must initialize them yourself.
+ $('[data-toggle="popover"]').popover()
+ })
+ .done();
+ });
})();