diff options
author | Aleš Smodiš <aless@guru.si> | 2015-09-24 17:40:10 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-09-24 17:40:10 +0200 |
commit | 23352d5f8a99d1457e64b76a958ca12dc789065d (patch) | |
tree | 6e964d85dd260978c16fd789125ca3051b562433 /js | |
parent | 3184e7f201af05429bedb4fb8a6300e024946c2a (diff) |
Make browser autodetection a little more resilient.
Diffstat (limited to 'js')
-rw-r--r-- | js/codeq/core.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/js/codeq/core.js b/js/codeq/core.js index 148cdeb..441c257 100644 --- a/js/codeq/core.js +++ b/js/codeq/core.js @@ -199,6 +199,7 @@ 'log': log, + 'availableLangs': [], // filled at boot from 'supportedLangs' 'supportedLangs': { 'en': 'English', 'sl': 'Slovenščina' @@ -371,12 +372,20 @@ $(document).ready(function () { // set the language - var lang = navigator.language || navigator.browserLanguage; - if (typeof lang === 'string') { - lang = lang.split('-')[0]; // truncate the language variant, in eg. en-US - if (lang in codeq.supportedLangs) codeq.lang = lang; + var navigatorLang = navigator.language || navigator.browserLanguage, // language reported by browser + lang = null, // the translation language that will be chosen + key; + if (typeof navigatorLang === 'string') { + navigatorLang = navigatorLang.split('-')[0]; // truncate the language variant, in eg. en-US } - codeq.setLang(lang); // initial language setting + else navigatorLang = 'en'; + for (key in codeq.supportedLangs) { + if (!codeq.supportedLangs.hasOwnProperty(key)) continue; + if (key === navigatorLang) lang = key; // we support the browser's language + codeq.availableLangs.push(key); + } + + codeq.setLang(lang || 'en'); // initial language setting // go to login codeq.globalStateMachine.transition('login'); |