aboutsummaryrefslogtreecommitdiff
path: root/web/load.js
diff options
context:
space:
mode:
authorRafael Guterres <guterresrafael@gmail.com>2016-12-21 01:23:01 -0200
committerRafael Guterres <guterresrafael@gmail.com>2016-12-21 22:29:41 -0200
commiteb5089cffdf6a3ed5e29fcce1b525b223ce5fe05 (patch)
treea774e4ba7103876a2417e9751be3ae7550d5bbde /web/load.js
parent0a465cee9200e0ae297aa9fe7eb9ac78be4636ad (diff)
downloadtrackermap-web-eb5089cffdf6a3ed5e29fcce1b525b223ce5fe05.tar.gz
trackermap-web-eb5089cffdf6a3ed5e29fcce1b525b223ce5fe05.tar.bz2
trackermap-web-eb5089cffdf6a3ed5e29fcce1b525b223ce5fe05.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.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/web/load.js b/web/load.js
index 0fe7ce54..03b85430 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) {