-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathninja.translator.js
152 lines (144 loc) · 5.77 KB
/
ninja.translator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
(function (ninja) {
var translator = 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 (!this.translate(language)) {
// Try to remove part after dash, for example cs-CZ -> cs
language = language.substr(0, language.indexOf('-'));
this.translate(language);
}
},
translate: function (culture) {
var dict = translator.translations[culture];
if (dict) {
// set current culture
translator.currentCulture = culture;
// update menu UI
for (var cult in translator.translations) {
var cultureElement = document.getElementById("culture" + cult);
if (cultureElement != null) {
cultureElement.setAttribute("class", "");
}
else {
console.log("DOM element not found: " + "culture" + cult);
}
document.getElementById("culture" + culture).setAttribute("class", "selected");
}
// apply translations
for (var id in dict) {
if (document.getElementById(id) && document.getElementById(id).value) {
document.getElementById(id).value = dict[id];
}
else if (document.getElementById(id)) {
document.getElementById(id).innerHTML = dict[id];
}
}
return true;
} else {
return false;
}
},
get: function (id) {
var translation = translator.translations[translator.currentCulture][id];
return translation;
},
translations: {
"en": {
// javascript alerts or messages
"testneteditionactivated": "TESTNET EDITION ACTIVATED",
"paperlabelbitcoinaddress": "Bitcoin Address:",
"paperlabelprivatekey": "Private Key:",
"paperlabelencryptedkey": "Encrypted Private Key (Password required)",
"bulkgeneratingaddresses": "Generating addresses... ",
"brainalertpassphrasetooshort": "The passphrase you entered is too short.\n\n",
"brainalertpassphrasewarning": "Warning: Choosing a strong passphrase is important to avoid brute force attempts to guess your passphrase and steal your bitcoins.",
"brainalertpassphrasedoesnotmatch": "The passphrase does not match the confirm passphrase.",
"detailalertnotvalidprivatekey": "The text you entered is not a valid Private Key",
"detailconfirmsha256": "The text you entered is not a valid Private Key!\n\nWould you like to use the entered text as a passphrase and create a Private Key using a SHA256 hash of the passphrase?\n\nWarning: Choosing a strong passphrase is important to avoid brute force attempts to guess your passphrase and steal your bitcoins.",
"detailbip38decryptbutton": "Decrypt BIP38", //TODO: please translate
"detailbip38encryptbutton": "Encrypt BIP38", //TODO: please translate
"bip38alertincorrectpassphrase": "Incorrect passphrase for this encrypted private key.",
"bip38alertpassphraserequired": "Passphrase required for BIP38 key",
"vanityinvalidinputcouldnotcombinekeys": "Invalid input. Could not combine keys.",
"vanityalertinvalidinputpublickeysmatch": "Invalid input. The Public Key of both entries match. You must input two different keys.",
"vanityalertinvalidinputcannotmultiple": "Invalid input. Cannot multiply two public keys. Select 'Add' to add two public keys to get a bitcoin address.",
"vanityprivatekeyonlyavailable": "Only available when combining two private keys",
"vanityalertinvalidinputprivatekeysmatch": "Invalid input. The Private Key of both entries match. You must input two different keys.",
// header and menu html
"singlewallet": "Single Wallet",
"paperwallet": "Paper Wallet",
"bulkwallet": "Bulk Wallet",
"brainwallet": "Brain Wallet",
"vanitywallet": "Vanity Wallet",
"splitwallet": "Split Wallet",
"detailwallet": "Wallet Details"
}
},
extractEnglishFromDomAndUpdateDictionary: function () {
var english = translator.translations["en"];
var spanish = translator.translations["es"];
var spanishClone = {};
for (var key in spanish) {
spanishClone[key] = spanish[key];
}
var newLang = {};
for (var key in english) {
newLang[key] = english[key];
delete spanishClone[key];
}
for (var key in spanishClone) {
if (document.getElementById(key)) {
if (document.getElementById(key).value) {
newLang[key] = document.getElementById(key).value;
}
else {
newLang[key] = document.getElementById(key).innerHTML;
}
}
}
translator.translations["en"] = newLang;
},
showEnglishJson: function () {
var english = ninja.translator.translations["en"];
var spanish = ninja.translator.translations["es"];
var spanishClone = {};
for (var key in spanish) {
spanishClone[key] = spanish[key];
}
var newLang = {};
for (var key in english) {
newLang[key] = english[key];
delete spanishClone[key];
}
for (var key in spanishClone) {
if (document.getElementById(key)) {
if (document.getElementById(key).value) {
newLang[key] = document.getElementById(key).value;
}
else {
newLang[key] = document.getElementById(key).innerHTML;
}
}
}
var div = document.createElement("div");
div.setAttribute("class", "englishjson");
div.innerHTML = "<h3>English Json</h3>";
var elem = document.createElement("textarea");
elem.setAttribute("rows", "15");
elem.setAttribute("cols", "110");
elem.setAttribute("wrap", "off");
var langJson = "{\n";
for (var key in newLang) {
langJson += "\t\"" + key + "\"" + ": " + "\"" + newLang[key].replace(/\"/g, "\\\"").replace(/\n/g, "\\n") + "\",\n";
}
langJson = langJson.substr(0, langJson.length - 2);
langJson += "\n}\n";
elem.innerHTML = langJson;
div.appendChild(elem);
document.body.appendChild(div);
}
};
})(ninja);