diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2016-12-15 11:39:14 +1100 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2016-12-15 11:39:14 +1100 |
commit | ede5137f6eafa4519830920765284b826e252a2f (patch) | |
tree | c1ab04520954733d85e1efb2a9017aedfc244852 | |
parent | e5abab4253217ed2a0d75cb9efd1ffe425b14f85 (diff) | |
download | BIP39-ede5137f6eafa4519830920765284b826e252a2f.tar.gz BIP39-ede5137f6eafa4519830920765284b826e252a2f.tar.zst BIP39-ede5137f6eafa4519830920765284b826e252a2f.zip |
Translation library can translate title attributes
-rw-r--r-- | src/js/translate.js | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/js/translate.js b/src/js/translate.js index 89512df..a62d92b 100644 --- a/src/js/translate.js +++ b/src/js/translate.js | |||
@@ -6,7 +6,8 @@ | |||
6 | // | 6 | // |
7 | // <div data-translate>Test</div> | 7 | // <div data-translate>Test</div> |
8 | // <div data-translate-html><em>keep em tag</em></div> | 8 | // <div data-translate-html><em>keep em tag</em></div> |
9 | // <input data-translate-placeholder placeholder="Example text"> | 9 | // <input data-translate-placeholder placeholder="Example placeholder"> |
10 | // <span data-translate-title title="Example title"></span> | ||
10 | // | 11 | // |
11 | // Obtain all the phrases to be translated via js debug console: | 12 | // Obtain all the phrases to be translated via js debug console: |
12 | // | 13 | // |
@@ -21,7 +22,8 @@ | |||
21 | // Translate.loadForeignPhrases("es", { | 22 | // Translate.loadForeignPhrases("es", { |
22 | // "Test": "Test in Spanish", | 23 | // "Test": "Test in Spanish", |
23 | // "<em>keep em tag</em>": "<em>keep em tag in Spanish</em>", | 24 | // "<em>keep em tag</em>": "<em>keep em tag in Spanish</em>", |
24 | // "Example text": "Example text in Spanish" | 25 | // "Example placeholder": "Example placeholder in Spanish" |
26 | // "Example title": "Example title in Spanish" | ||
25 | // }); | 27 | // }); |
26 | // | 28 | // |
27 | // In your UI put a listener for clicking on the Spanish button: | 29 | // In your UI put a listener for clicking on the Spanish button: |
@@ -72,10 +74,21 @@ Translate = new (function() { | |||
72 | }, | 74 | }, |
73 | } | 75 | } |
74 | 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 | |||
75 | // Get elements to be translated | 87 | // Get elements to be translated |
76 | var allEls = getEls(text) | 88 | var allEls = getEls(text) |
77 | .concat(getEls(html)) | 89 | .concat(getEls(html)) |
78 | .concat(getEls(placeholder)); | 90 | .concat(getEls(placeholder)) |
91 | .concat(getEls(title)); | ||
79 | 92 | ||
80 | // Provides access to phrases from a non-default language. | 93 | // Provides access to phrases from a non-default language. |
81 | // See phrases_en.js for example usage. | 94 | // See phrases_en.js for example usage. |