use browser language setting as first choice
authorMoritz Warning <moritzwarning@web.de>
Sun, 29 Mar 2020 18:00:59 +0000 (20:00 +0200)
committerMoritz Warning <moritzwarning@web.de>
Sun, 29 Mar 2020 18:00:59 +0000 (20:00 +0200)
index.html
index.js

index 5e99566820f75c97b470d9c224e41a3419fdee6b..5d4a25629fffb1791cf326eb14e6f4ae3b32c6b2 100644 (file)
@@ -16,7 +16,7 @@
                <img src="logo.png" alt="Logo">
                <div style="flex-grow: 1;"></div>
 
-               <select id="language-selection" onchange="current_language=this.children[this.selectedIndex].value; translate();" size="1">
+               <select id="language-selection" onchange="config.language=this.children[this.selectedIndex].value; translate();" size="1">
                        <option value="en">English</option>
                        <option value="de">Deutsch</option>
                </select>
index fadbfe79d03565ffcd420afb79298818c2441ea9..b652815187c7d0e024e080c200ecdb30241844d2 100644 (file)
--- 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();