OLD | NEW |
---|---|
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 var l10n = l10n || {}; | 6 var l10n = l10n || {}; |
7 | 7 |
8 /** | 8 /** |
9 * Localize a tag, returning the tag itself and logging an error if no | 9 * Localize a tag, returning the tag itself and logging an error if no |
10 * translation exists. | 10 * translation exists. |
(...skipping 10 matching lines...) Expand all Loading... | |
21 } | 21 } |
22 console.error('Missing translation for "' + tag + '"'); | 22 console.error('Missing translation for "' + tag + '"'); |
23 return tag; | 23 return tag; |
24 }; | 24 }; |
25 | 25 |
26 /** | 26 /** |
27 * Localize an element by setting its innerText according to the specified tag | 27 * Localize an element by setting its innerText according to the specified tag |
28 * and an optional set of substitutions. | 28 * and an optional set of substitutions. |
29 * | 29 * |
30 * @param {Element} element The element to localize. | 30 * @param {Element} element The element to localize. |
31 * @param {string} tag The localization tag. | 31 * @param {string|remoting.Error} tagOrError The localization tag or |
32 * an Error object containing the tag. | |
Jamie
2015/03/13 17:56:17
This should just be a string, and the caller shoul
Jamie
2015/03/13 20:26:01
Please address this comment.
John Williams
2015/03/13 22:40:30
Done.
| |
32 * @param {(string|Array)=} opt_substitutions An optional set of substitution | 33 * @param {(string|Array)=} opt_substitutions An optional set of substitution |
33 * strings corresponding to the "placeholders" attributes in messages.json. | 34 * strings corresponding to the "placeholders" attributes in messages.json. |
34 * @param {boolean=} opt_asHtml If true, set innerHTML instead of innerText. | 35 * @param {boolean=} opt_asHtml If true, set innerHTML instead of innerText. |
35 * This parameter should be used with caution. | 36 * This parameter should be used with caution. |
36 * @return {boolean} True if the localization was successful; false otherwise. | 37 * @return {boolean} True if the localization was successful; false otherwise. |
37 */ | 38 */ |
38 l10n.localizeElementFromTag = function(element, tag, opt_substitutions, | 39 l10n.localizeElementFromTag = function(element, tagOrError, opt_substitutions, |
39 opt_asHtml) { | 40 opt_asHtml) { |
41 if (tagOrError == null) { | |
42 return false; | |
43 } | |
44 var tag = typeof tagOrError == 'string' ? | |
45 /** @type {string} */ (tagOrError) : | |
46 tagOrError.getTagForLocalization(); | |
40 var translation = l10n.getTranslationOrError(tag, opt_substitutions); | 47 var translation = l10n.getTranslationOrError(tag, opt_substitutions); |
41 if (opt_asHtml) { | 48 if (opt_asHtml) { |
42 element.innerHTML = translation; | 49 element.innerHTML = translation; |
43 } else { | 50 } else { |
44 element.innerText = translation; | 51 element.innerText = translation; |
45 } | 52 } |
46 return translation != null; | 53 return translation != null; |
47 }; | 54 }; |
48 | 55 |
49 /** | 56 /** |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 } | 103 } |
97 var titleTag = element.getAttribute('i18n-title'); | 104 var titleTag = element.getAttribute('i18n-title'); |
98 if (titleTag) { | 105 if (titleTag) { |
99 element.title = l10n.getTranslationOrError(titleTag, substitutions); | 106 element.title = l10n.getTranslationOrError(titleTag, substitutions); |
100 } else { | 107 } else { |
101 l10n.localizeElement(element, substitutions, | 108 l10n.localizeElement(element, substitutions, |
102 substitutions.length != 0); | 109 substitutions.length != 0); |
103 } | 110 } |
104 } | 111 } |
105 }; | 112 }; |
OLD | NEW |