From 48777d73611dce9f873a747b7ae4648fecbf2868 Mon Sep 17 00:00:00 2001 From: onovy Date: Sun, 19 Jan 2014 22:00:13 +0100 Subject: [PATCH] Try to auto-detect user language and translate web. Conflicts: bitaddress.org.html src/ninja.onload.js --- index.html | 16 ++++++++++++++++ src/ninja.onload.js | 4 +++- src/ninja.translator.js | 13 +++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) 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) {