Browse Source

Merge pull request #4 from iShift/master

add language trigger
master
iHedgehog 11 years ago
parent
commit
022449f94b
  1. 11
      js/interface_localization.js
  2. 33
      options.html

11
js/interface_localization.js

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

33
options.html

@ -48,6 +48,25 @@
<div class="wrapper"> <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="sounds">
<div class="module"> <div class="module">
@ -91,7 +110,17 @@
</select> </select>
</form> </form>
</div> </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> </body>
</html> </html>

Loading…
Cancel
Save