diff options
author | Rafael Guterres <guterresrafael@gmail.com> | 2016-12-21 01:23:01 -0200 |
---|---|---|
committer | Rafael Guterres <guterresrafael@gmail.com> | 2016-12-21 01:23:01 -0200 |
commit | 1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35 (patch) | |
tree | ca46ca529083c02e330f02098e618eba88c286b6 /web/load.js | |
parent | 0a465cee9200e0ae297aa9fe7eb9ac78be4636ad (diff) | |
download | etbsa-traccar-web-1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35.tar.gz etbsa-traccar-web-1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35.tar.bz2 etbsa-traccar-web-1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35.zip |
Added support to array "window.navigator.languages" to use rank of browser languages.
Definition of "locale.language" changed to make more tests.
Diffstat (limited to 'web/load.js')
-rw-r--r-- | web/load.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/web/load.js b/web/load.js index 0fe7ce5..c84a4a3 100644 --- a/web/load.js +++ b/web/load.js @@ -77,13 +77,28 @@ localeParameter = window.location.search.match(/locale=([^&#]+)/); locale.language = localeParameter && localeParameter[1]; - if (locale.language === undefined) { - locale.language = window.navigator.userLanguage || window.navigator.language; - locale.language = locale.language.substr(0, 2); + if (!(locale.language in locale.languages)) { + if (window.navigator.languages !== undefined) { + for (var i = 0; i < window.navigator.languages.length; i ++) { + var language = window.navigator.languages[i].replace("-", "_"); + if (language in locale.languages) { + locale.language = language; + break; + } + } + } } - if (!(locale.language in locale.languages)) { - locale.language = 'en'; // default + var language = window.navigator.userLanguage || window.navigator.language; + if (language in locale.languages) { + locale.language = language; + } else if (language.replace("-", "_") in locale.languages) { + locale.language = language.replace("-", "_"); + } else if (language.substr(0, 2) in locale.languages) { + locale.language = language.substr(0, 2); + } else { + locale.language = "en"; // default + } } window.addEventListener('load', function (event) { |