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