diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-12-22 16:53:51 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-22 16:53:51 +1300 |
commit | 0c7ff9b0366abe63f9c690fa4507b8f28af4bd7b (patch) | |
tree | f92644c27670e0c7f2f210905ee4b0e21916425c /web/load.js | |
parent | 19d6e1c9cc916ed4c1ed72fe168909770a657db2 (diff) | |
parent | ed9e15033dc95c08126f9b257abe784f32c69fb0 (diff) | |
download | trackermap-web-0c7ff9b0366abe63f9c690fa4507b8f28af4bd7b.tar.gz trackermap-web-0c7ff9b0366abe63f9c690fa4507b8f28af4bd7b.tar.bz2 trackermap-web-0c7ff9b0366abe63f9c690fa4507b8f28af4bd7b.zip |
Merge pull request #363 from guterresrafael/master
locale by browser preferences
Diffstat (limited to 'web/load.js')
-rw-r--r-- | web/load.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/web/load.js b/web/load.js index c329295b..cd012f18 100644 --- a/web/load.js +++ b/web/load.js @@ -77,13 +77,19 @@ 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)) { - locale.language = 'en'; // default + var languages = window.navigator.languages !== undefined ? window.navigator.languages.slice() : []; + var language = window.navigator.userLanguage || window.navigator.language; + languages.push(language); + languages.push(language.substr(0,2)); + languages.push("en"); //default + for (var i = 0; i < languages.length; i ++) { + var language = languages[i].replace("-", "_"); + if (language in locale.languages) { + locale.language = language; + break; + } + } } window.addEventListener('load', function (event) { |