From 1fe2b7a2411e27f172dd08ebe7bc20f5cdae4b35 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Date: Wed, 21 Dec 2016 01:23:01 -0200 Subject: Added support to array "window.navigator.languages" to use rank of browser languages. Definition of "locale.language" changed to make more tests. --- web/load.js | 25 ++++++++++++++++++++----- 1 file 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) { -- cgit v1.2.3