diff options
author | Marko Pušnik <marko.pusnik@guru.si> | 2015-09-30 19:07:37 +0200 |
---|---|---|
committer | Marko Pušnik <marko.pusnik@guru.si> | 2015-09-30 19:07:37 +0200 |
commit | 8bb68a1e979022ead00535c25403b341f2cb24bb (patch) | |
tree | 0ad16cf9acb81cbb6f8484f32fed657e8c66dabb /js/codeq/core.js | |
parent | ba6135a83273c625097fe7cdb59319a51acca31e (diff) | |
parent | 0da1117cfc28688633be7b8382aa60435bf740eb (diff) |
Merge branch 'master' of odie.guru.si:codeq-web
Conflicts:
index.html
Diffstat (limited to 'js/codeq/core.js')
-rw-r--r-- | js/codeq/core.js | 63 |
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(); + }); })(); |