From: Moritz Warning Date: Sun, 29 Mar 2020 18:00:59 +0000 (+0200) Subject: use browser language setting as first choice X-Git-Tag: v2.2.0~16 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=44ad3426f83a846ab39a69ca007b0c3b5fb0de42;p=web%2Ffirmware-selector-openwrt-org.git use browser language setting as first choice --- diff --git a/index.html b/index.html index 5e99566..5d4a256 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ Logo
- diff --git a/index.js b/index.js index fadbfe7..b652815 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ var current_model = {}; -var current_language = config.language; function $(id) { return document.getElementById(id); @@ -125,7 +124,7 @@ function setupSelectList(select, items, onselection) { // Change the translation of the entire document function translate() { - var mapping = translations[current_language]; + var mapping = translations[config.language]; for (var tr in mapping) { Array.from(document.getElementsByClassName(tr)) .forEach(e => { e.innerText = mapping[tr]; }) @@ -376,4 +375,11 @@ if (config.asu_url) { // hide fields updateImages(); + +var user_lang = (navigator.language || navigator.userLanguage).split('-')[0]; +if (user_lang in translations) { + config.language = user_lang; + $('language-selection').value = user_lang; +} + translate();