diff options
-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 0fe7ce54..c84a4a31 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) { |