add language trigger

This commit is contained in:
Shift 2014-03-09 15:49:00 +04:00
parent 814b4cf2a9
commit 9dcc738b5f
2 changed files with 42 additions and 2 deletions

View File

@ -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{
// 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();

View File

@ -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">
@ -91,7 +110,17 @@
</select>
</form>
</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>