diff --git a/bitaddress.org.html b/bitaddress.org.html index 7f56beb..dbe1665 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -7488,6 +7488,17 @@ ninja.foreachSerialized = function (collection, whatToDo, onComplete) { ninja.translator = { currentCulture: "en", + autodetectTranslation: function() { + // window.navigator.language for Firefox / Chrome / Opera Safari + // window.navigator.userLanguage for IE + var language = window.navigator.language || window.navigator.userLanguage; + if (!ninja.translator.translate(language)) { + // Try to remove part after dash, for example cs-CZ -> cs + language = language.substr(0, language.indexOf('-')); + ninja.translator.translate(language); + } + }, + translate: function (culture) { var dict = ninja.translator.translations[culture]; if (dict) { @@ -7507,6 +7518,9 @@ ninja.translator = { document.getElementById(id).innerHTML = dict[id]; } } + return true; + } else { + return false; } }, @@ -9900,6 +9914,8 @@ if (ninja.getQueryString()["asyncunittests"] == "true" || ninja.getQueryString() // change language if (ninja.getQueryString()["culture"] != undefined) { ninja.translator.translate(ninja.getQueryString()["culture"]); +} else { + ninja.translator.autodetectTranslation(); } // testnet, check if testnet edition should be activated if (ninja.getQueryString()["testnet"] == "true" || ninja.getQueryString()["testnet"] == "1") { diff --git a/src/ninja.onload.js b/src/ninja.onload.js index 2372b8e..07b53f2 100644 --- a/src/ninja.onload.js +++ b/src/ninja.onload.js @@ -10,6 +10,8 @@ if (ninja.getQueryString()["asyncunittests"] == "true" || ninja.getQueryString() // change language if (ninja.getQueryString()["culture"] != undefined) { ninja.translator.translate(ninja.getQueryString()["culture"]); +} else { + ninja.translator.autodetectTranslation(); } // testnet, check if testnet edition should be activated if (ninja.getQueryString()["testnet"] == "true" || ninja.getQueryString()["testnet"] == "1") { diff --git a/src/ninja.translator.js b/src/ninja.translator.js index d98fb57..0bf4394 100644 --- a/src/ninja.translator.js +++ b/src/ninja.translator.js @@ -1,6 +1,17 @@ ninja.translator = { currentCulture: "en", + autodetectTranslation: function() { + // window.navigator.language for Firefox / Chrome / Opera Safari + // window.navigator.userLanguage for IE + var language = window.navigator.language || window.navigator.userLanguage; + if (!ninja.translator.translate(language)) { + // Try to remove part after dash, for example cs-CZ -> cs + language = language.substr(0, language.indexOf('-')); + ninja.translator.translate(language); + } + }, + translate: function (culture) { var dict = ninja.translator.translations[culture]; if (dict) { @@ -20,6 +31,9 @@ ninja.translator = { document.getElementById(id).innerHTML = dict[id]; } } + return true; + } else { + return false; } },