Browse Source

add language trigger

master
Shift 11 years ago
parent
commit
9dcc738b5f
  1. 11
      js/interface_localization.js
  2. 29
      options.html

11
js/interface_localization.js

@ -6,6 +6,9 @@ @@ -6,6 +6,9 @@
// translators: add your language code here such as "es" for Spanish, "ru" for Russian
var knownLanguages = ["en","nl","it","fr","ru","de","zh"];
// get localstorage language
var preferredLanguagel = localStorage.getItem("preferredLanguagel");
// detect language with JavaScript
var preferredLanguage = window.navigator.userLanguage || window.navigator.language || "en";
if(knownLanguages.indexOf(preferredLanguage) > -1){
@ -20,6 +23,14 @@ else{ @@ -20,6 +23,14 @@ else{
// did not find match
preferredLanguage = "en";
}
if (preferredLanguage !== preferredLanguagel) {
console.log('use language from localstorage');
var preferredLanguage = preferredLanguagel;
}
else {
console.log('use auto language');
}
// set up Polyglot
polyglot = new Polyglot();

29
options.html

@ -48,6 +48,25 @@ @@ -48,6 +48,25 @@
<div class="wrapper">
<div class="language">
<div class="module">
<p> Language </p>
<div>
<form action="" id="choselanguage">
<p>Use language</p>
<select onchange="savelang();" name="" id="language">
<option value="en">English</option>
<option value="ru">Russian</option>
<option value="zh">zh</option>
<option value="de">de</option>
<option value="fr">fr</option>
<option value="it">it</option>
<option value="nl">nl</option>
</select>
</form>
</div>
<div class="sounds">
<div class="module">
@ -93,5 +112,15 @@ @@ -93,5 +112,15 @@
</div>
<script>
function savelang () {
var preferredLanguagel = document.getElementById('language').value;
localStorage.setItem('preferredLanguagel', preferredLanguagel);
document.location.reload()
}
var preferredLanguagel = localStorage.getItem("preferredLanguagel");
document.getElementById('language').value = preferredLanguagel;
</script>
</body>
</html>

Loading…
Cancel
Save