aboutsummaryrefslogtreecommitdiff
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 01:23:01 -0200
commit1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35 (patch)
treeca46ca529083c02e330f02098e618eba88c286b6
parent0a465cee9200e0ae297aa9fe7eb9ac78be4636ad (diff)
downloadtrackermap-web-1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35.tar.gz
trackermap-web-1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35.tar.bz2
trackermap-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.
-rw-r--r--web/load.js25
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) {