aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2017-10-02 14:09:32 +1100
committerIan Coleman <coleman.ian@gmail.com>2017-10-02 14:09:32 +1100
commitfb00a22d3fbce70c8694419a7378ece7dd93e283 (patch)
tree24ff9af46576a7b00af8a991401fa0ba98ab6f3c /src/js
parent73b8724a6f83b597e4003b4bdd8f395fb94eda79 (diff)
downloadBIP39-fb00a22d3fbce70c8694419a7378ece7dd93e283.tar.gz
BIP39-fb00a22d3fbce70c8694419a7378ece7dd93e283.tar.zst
BIP39-fb00a22d3fbce70c8694419a7378ece7dd93e283.zip
Remove hand-rolled translation library
Diffstat (limited to 'src/js')
-rw-r--r--src/js/phrases_en.js94
-rw-r--r--src/js/translate.js153
2 files changed, 0 insertions, 247 deletions
diff --git a/src/js/phrases_en.js b/src/js/phrases_en.js
deleted file mode 100644
index 7181544..0000000
--- a/src/js/phrases_en.js
+++ /dev/null
@@ -1,94 +0,0 @@
1Translate.loadForeignPhrases("en",
2{
3 "<code>m/44'/0'/0'/0</code> generates public addresses": "<code>m/44'/0'/0'/0</code> generates public addresses",
4 "<code>m/44'/0'/0'/1</code> generates change addresses": "<code>m/44'/0'/0'/1</code> generates change addresses",
5 "<code>m/44'/0'/0'</code> generates extended keys for import / export": "<code>m/44'/0'/0'</code> generates extended keys for import / export",
6 "<code>m/44'/0'/1'</code> for the next account. Continue incrementing for more accounts (most use a single account).": "<code>m/44'/0'/1'</code> for the next account. Continue incrementing for more accounts (most use a single account).",
7 "Accepts binary, base 6, 6-sided dice, base 10, hexadecimal, cards": "Accepts binary, base 6, 6-sided dice, base 10, hexadecimal, cards",
8 "Account": "Account",
9 "Address": "Address",
10 "Alternatively, download the file from the repository": "Alternatively, download the file from the repository",
11 "BIP32 Derivation Path": "BIP32 Derivation Path",
12 "BIP32 Extended Key": "BIP32 Extended Key",
13 "BIP32 Extended Key (addresses only)": "BIP32 Extended Key (addresses only)",
14 "BIP32 Root Key": "BIP32 Root Key",
15 "BIP39 Mnemonic": "BIP39 Mnemonic",
16 "BIP39 Passphrase (optional)": "BIP39 Passphrase (optional)",
17 "BIP39 Seed": "BIP39 Seed",
18 "Base 10": "Base 10",
19 "Base 6": "Base 6",
20 "Be careful - it can be easy to make mistakes if you don't know what you're doing.": "Be careful - it can be easy to make mistakes if you don't know what you're doing.",
21 "Binary": "Binary",
22 "Bitcoin Core": "Bitcoin Core",
23 "Bits Per Event": "Bits Per Event",
24 "Block Explorers": "Block Explorers",
25 "Can be used with": "Can be used with",
26 "Card": "Card",
27 "Coin": "Coin",
28 "Dice": "Dice",
29 "Do <strong>NOT</strong> use phrases from books, lyrics from songs, your birthday or steet address, keyboard mashing, or anything you <i>think</i> is random, because chances are overwhelming it isn't random enough for the needs of this tool.": "Do <strong>NOT</strong> use phrases from books, lyrics from songs, your birthday or steet address, keyboard mashing, or anything you <i>think</i> is random, because chances are overwhelming it isn't random enough for the needs of this tool.",
30 "Double-click that file to open it in a browser on any offline computer.": "Double-click that file to open it in a browser on any offline computer.",
31 "Entropy": "Entropy",
32 "Entropy Type": "Entropy Type",
33 "Entropy is an advanced feature. Your mnemonic may be insecure if this feature is used incorrectly.": "Entropy is an advanced feature. Your mnemonic may be insecure if this feature is used incorrectly.",
34 "Entropy values must be sourced from a <a href=\"https://en.wikipedia.org/wiki/Random_number_generation\" target=\"_blank\">strong source of randomness</a>.": "Entropy values must be sourced from a <a href=\"https://en.wikipedia.org/wiki/Random_number_generation\" target=\"_blank\">strong source of randomness</a>.",
35 "Event Count": "Event Count",
36 "External / Internal": "External / Internal",
37 "Filtered Entropy": "Filtered Entropy",
38 "For more info see the <a href=\"http://www.mycelium.com/\" target=\"_blank\">Mycelium Wallet homepage</a>": "For more info see the <a href=\"http://www.mycelium.com/\" target=\"_blank\">Mycelium Wallet homepage</a>",
39 "For more info see the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki\" target=\"_blank\">BIP39 spec</a>.": "For more info see the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki\" target=\"_blank\">BIP39 spec</a>.",
40 "For more info see the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki\" target=\"_blank\">BIP44 spec</a>.": "For more info see the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki\" target=\"_blank\">BIP44 spec</a>.",
41 "For more info see the <a href=\"https://github.com/bitcoin/bitcoin/pull/8035\" target=\"_blank\">Bitcoin Core BIP32 implementation</a>": "For more info see the <a href=\"https://github.com/bitcoin/bitcoin/pull/8035\" target=\"_blank\">Bitcoin Core BIP32 implementation</a>",
42 "For more info see the BIP32 spec": "For more info see the BIP32 spec",
43 "From entropy length (3 words per 32 bits)": "From entropy length (3 words per 32 bits)",
44 "Generate a random mnemonic, or enter your own below": "Generate a random mnemonic, or enter your own below",
45 "Get the source code from the repository": "Get the source code from the repository",
46 "Hex": "Hex",
47 "Hierarchical Deterministic Wallets": "Hierarchical Deterministic Wallets",
48 "If cryptographic randomness isn't available in your browser, this page will show a warning and the generate button will not work.": "If cryptographic randomness isn't available in your browser, this page will show a warning and the generate button will not work.",
49 "In that case you might choose to use your own source of entropy.": "In that case you might choose to use your own source of entropy.",
50 "In your browser, select file save-as, and save this page as a file.": "In your browser, select file save-as, and save this page as a file.",
51 "Libraries": "Libraries",
52 "Mnemonic Language": "Mnemonic Language",
53 "Mnemonic Length": "Mnemonic Length",
54 "Mnemonic code for generating deterministic keys": "Mnemonic code for generating deterministic keys",
55 "More info": "More info",
56 "Multi-Account Hierarchy for Deterministic Wallets": "Multi-Account Hierarchy for Deterministic Wallets",
57 "Mycelium Wallet": "Mycelium Wallet",
58 "Note these addreses are derived from the BIP32 Extended Key": "Note these addreses are derived from the BIP32 Extended Key",
59 "Offline Usage": "Offline Usage",
60 "Only enter the <code>xpub</code> extended key into block explorer search fields, never the <code>xprv</code> key.": "Only enter the <code>xpub</code> extended key into block explorer search fields, never the <code>xprv</code> key.",
61 "Path": "Path",
62 "Private Key": "Private Key",
63 "Private Keys": "Private Keys",
64 "Public Key": "Public Key",
65 "Purpose": "Purpose",
66 "Raw Binary": "Raw Binary",
67 "Read more": "Read more",
68 "Read more at the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki\" target=\"_blank\">official BIP32 spec</a>": "Read more at the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki\" target=\"_blank\">official BIP32 spec</a>",
69 "Read more at the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki\">official BIP39 spec</a>": "Read more at the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki\">official BIP39 spec</a>",
70 "Read more at the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki\" target=\"_blank\">official BIP44 spec</a>": "Read more at the <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki\" target=\"_blank\">official BIP44 spec</a>",
71 "See the demo at <a href=\"http://bip32.org/\" target=\"_blank\">bip32.org</a>": "See the demo at <a href=\"http://bip32.org/\" target=\"_blank\">bip32.org</a>",
72 "Show": "Show",
73 "Show more rows": "Show more rows",
74 "Strength": "Strength",
75 "Supply my own source of entropy": "Supply my own source of entropy",
76 "The built in random generator can generally be trusted more than your own intuition about randomness.": "The built in random generator can generally be trusted more than your own intuition about randomness.",
77 "The random mnemonic generator on this page uses a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues\" target=\"_blank\">cryptographically secure random number generator</a>.": "The random mnemonic generator on this page uses a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues\" target=\"_blank\">cryptographically secure random number generator</a>.",
78 "This means flipping a fair coin, rolling a fair dice, noise measurements etc.": "This means flipping a fair coin, rolling a fair dice, noise measurements etc.",
79 "This project is 100% open-source code": "This project is 100% open-source code",
80 "Toggle": "Toggle",
81 "Total Bits": "Total Bits",
82 "Use hardened addresses": "Use hardened addresses",
83 "Use path <code>m/0'/0'</code> with hardened addresses.": "Use path <code>m/0'/0'</code> with hardened addresses.",
84 "Use path <code>m/44'/0'/0'</code>.": "Use path <code>m/44'/0'/0'</code>.",
85 "Use private keys at <a href=\"https://web.archive.org/web/20150707020924/https://brainwallet.org/\" target=\"_blank\">brainwallet.org</a>.": "Use private keys at <a href=\"https://web.archive.org/web/20150707020924/https://brainwallet.org/\" target=\"_blank\">brainwallet.org</a>.",
86 "Valid entropy values include:": "Valid entropy values include:",
87 "Warning": "Warning",
88 "Word Count": "Word Count",
89 "You are not a good source of entropy.": "You are not a good source of entropy.",
90 "You can enter an existing BIP39 mnemonic, or generate a new random one. Typing your own twelve words will probably not work how you expect, since the words require a particular structure (the last word is a checksum).": "You can enter an existing BIP39 mnemonic, or generate a new random one. Typing your own twelve words will probably not work how you expect, since the words require a particular structure (the last word is a checksum).",
91 "You can use this tool without having to be online.": "You can use this tool without having to be online.",
92 "words": "words"
93}
94);
diff --git a/src/js/translate.js b/src/js/translate.js
deleted file mode 100644
index a62d92b..0000000
--- a/src/js/translate.js
+++ /dev/null
@@ -1,153 +0,0 @@
1// An extremely basic translation library
2//
3// Example usage:
4//
5// Set some html to be translated. Do this using the 'data-translate' attribute:
6//
7// <div data-translate>Test</div>
8// <div data-translate-html><em>keep em tag</em></div>
9// <input data-translate-placeholder placeholder="Example placeholder">
10// <span data-translate-title title="Example title"></span>
11//
12// Obtain all the phrases to be translated via js debug console:
13//
14// Translate.phrasesAsJson();
15//
16// Use that template to translate the phrases into another language.
17// Leave the key the same. Change the value to the new language.
18//
19// Create a js file to load the new phrases. In this example for Spanish,
20// es.js will contain the following code:
21//
22// Translate.loadForeignPhrases("es", {
23// "Test": "Test in Spanish",
24// "<em>keep em tag</em>": "<em>keep em tag in Spanish</em>",
25// "Example placeholder": "Example placeholder in Spanish"
26// "Example title": "Example title in Spanish"
27// });
28//
29// In your UI put a listener for clicking on the Spanish button:
30//
31// mySpanishButton.addEventListener("click", function() {
32// Translate.setLanguage("es");
33// });
34// myEnglishButton.addEventListener("click", function() {
35// Translate.setLanguage("en");
36// });
37
38Translate = new (function() {
39
40 var defaultLanguage = "en";
41
42 var allPhrases = {};
43 allPhrases[defaultLanguage] = {};
44
45 // Node types
46
47 var text = {
48 selector: "[data-translate]",
49 getKey: function() {
50 return this.textContent.trim().replace(/\s+/g, " ");
51 },
52 setPhrase: function(p) {
53 this.textContent = p;
54 },
55 }
56
57 var html = {
58 selector: "[data-translate-html]",
59 getKey: function() {
60 return this.innerHTML.trim().replace(/\s+/g, " ");
61 },
62 setPhrase: function(p) {
63 this.innerHTML = p;
64 },
65 }
66
67 var placeholder = {
68 selector: "[data-translate-placeholder]",
69 getKey: function() {
70 return this.getAttribute("placeholder").trim().replace(/\s+/g, " ");
71 },
72 setPhrase: function(p) {
73 this.setAttribute("placeholder", p);
74 },
75 }
76
77 var title = {
78 selector: "[data-translate-title]",
79 getKey: function() {
80 return this.getAttribute("title").trim().replace(/\s+/g, " ");
81 },
82 setPhrase: function(p) {
83 this.setAttribute("title", p);
84 },
85 }
86
87 // Get elements to be translated
88 var allEls = getEls(text)
89 .concat(getEls(html))
90 .concat(getEls(placeholder))
91 .concat(getEls(title));
92
93 // Provides access to phrases from a non-default language.
94 // See phrases_en.js for example usage.
95 this.loadForeignPhrases = function(language, phrases) {
96 allPhrases[language] = phrases;
97 }
98
99 // Displays a different language, eg "en" or "fr"
100 this.setLanguage = function(language) {
101 for (var i=0; i<allEls.length; i++) {
102 var el = allEls[i];
103 var key = el.key;
104 if (!(language in allPhrases)) {
105 console.log(language + " not in allPhrases");
106 return;
107 }
108 if (!(key in allPhrases[language])) {
109 console.log(language + " does not contain phrase: " + key);
110 return;
111 }
112 var phrase = allPhrases[language][key];
113 el.setPhrase(phrase);
114 }
115 }
116
117 // Converts the phrases to a key-pair json file.
118 // This is a good way to export phrases for use in translation tools.
119 this.phrasesAsJson = function(language) {
120 var keys = [];
121 for (var i=0; i<allEls.length; i++) {
122 var el = allEls[i];
123 var key = el.key;
124 keys.push(key);
125 }
126 keys.sort();
127 var output = {};
128 for (var i=0; i<keys.length; i++) {
129 var key = keys[i];
130 var translated = "";
131 if (language in allPhrases && key in allPhrases[language]) {
132 translated = allPhrases[language][key];
133 }
134 output[key] = translated;
135 }
136 return JSON.stringify(output, null, 2);
137 }
138
139 function getEls(nodeType) {
140 var nodes = document.querySelectorAll(nodeType.selector);
141 var els = [];
142 for (var i=0; i<nodes.length; i++) {
143 var node = nodes[i];
144 node.getKey = nodeType.getKey;
145 node.setPhrase = nodeType.setPhrase;
146 node.key = node.getKey();
147 allPhrases[defaultLanguage][node.key] = node.key;
148 els.push(node);
149 }
150 return els;
151 }
152
153})();