diff --git a/index.html b/index.html index 45bad4c..31d9b43 100644 --- a/index.html +++ b/index.html @@ -10968,6 +10968,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) { @@ -10987,7 +10998,9 @@ ninja.translator = { document.getElementById(id).innerHTML = dict[id]; } } + return true; } + return false; }, get: function (id) { @@ -12332,6 +12345,8 @@ ninja.wallets.donate = { // change language if (ninja.getQueryString()["culture"] != undefined) { ninja.translator.translate(ninja.getQueryString()["culture"]); +} else { + ninja.translator.autodetectTranslation(); } if (ninja.getQueryString()["showseedpool"] == "true" || ninja.getQueryString()["showseedpool"] == "1") { document.getElementById("seedpoolarea").style.display = "block"; @@ -12430,6 +12445,7 @@ if (ninja.getQueryString()["i18nextract"]) { ninja.envSecurityCheck(); ninja.browserSecurityCheck(); + diff --git a/src/ninja.onload.js b/src/ninja.onload.js index 44ce11c..83023a8 100644 --- a/src/ninja.onload.js +++ b/src/ninja.onload.js @@ -1,6 +1,8 @@ // change language if (ninja.getQueryString()["culture"] != undefined) { ninja.translator.translate(ninja.getQueryString()["culture"]); +} else { + ninja.translator.autodetectTranslation(); } if (ninja.getQueryString()["showseedpool"] == "true" || ninja.getQueryString()["showseedpool"] == "1") { document.getElementById("seedpoolarea").style.display = "block"; @@ -98,4 +100,4 @@ if (ninja.getQueryString()["i18nextract"]) { } ninja.envSecurityCheck(); -ninja.browserSecurityCheck(); \ No newline at end of file +ninja.browserSecurityCheck(); diff --git a/src/ninja.translator.js b/src/ninja.translator.js index a4b7dae..be5e817 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,7 +31,9 @@ ninja.translator = { document.getElementById(id).innerHTML = dict[id]; } } + return true; } + return false; }, get: function (id) {