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 an element by setting its innerText according to the specified tag | 9 * Localize an element by setting its innerText according to the specified tag |
10 * and an optional set of substitutions. | 10 * and an optional set of substitutions. |
11 * @param {Element} element The element to localize. | 11 * @param {Element} element The element to localize. |
12 * @param {string} tag The localization tag. | 12 * @param {string} tag The localization tag. |
13 * @param {(string|Array)=} opt_substitutions An optional set of substitution | 13 * @param {(string|Array)=} opt_substitutions An optional set of substitution |
14 * strings corresponding to the "placeholders" attributes in messages.json. | 14 * strings corresponding to the "placeholders" attributes in messages.json. |
15 * @param {boolean=} opt_asHtml If true, set innerHTML instead of innerText. | 15 * @param {boolean=} opt_asHtml If true, set innerHTML instead of innerText. |
16 * This parameter should be used with caution. | 16 * This parameter should be used with caution. |
17 * @return {boolean} True if the localization was successful; false otherwise. | 17 * @return {boolean} True if the localization was successful; false otherwise. |
18 */ | 18 */ |
19 l10n.localizeElementFromTag = function(element, tag, opt_substitutions, | 19 l10n.localizeElementFromTag = function(element, tag, opt_substitutions, |
20 opt_asHtml) { | 20 opt_asHtml) { |
21 var translation = chrome.i18n.getMessage(tag, opt_substitutions); | 21 var translation = chrome.i18n.getMessage(tag, opt_substitutions); |
22 if (translation) { | 22 if (!translation) { |
23 if (opt_asHtml) { | 23 console.error('Missing translation for "' + tag + '":', element); |
24 element.innerHTML = translation; | 24 translation = tag; // Make errors more obvious |
25 } else { | 25 } |
26 element.innerText = translation; | 26 if (opt_asHtml) { |
27 } | 27 element.innerHTML = translation; |
28 } else { | 28 } else { |
29 console.error('Missing translation for "' + tag + '":', element); | 29 element.innerText = translation; |
30 } | 30 } |
31 return translation != null; | 31 return translation != null; |
32 }; | 32 }; |
33 | 33 |
34 /** | 34 /** |
35 * Localize an element by setting its innerText according to its i18n-content | 35 * Localize an element by setting its innerText according to its i18n-content |
36 * attribute, and an optional set of substitutions. | 36 * attribute, and an optional set of substitutions. |
37 * @param {Element} element The element to localize. | 37 * @param {Element} element The element to localize. |
38 * @param {(string|Array)=} opt_substitutions An optional set of substitution | 38 * @param {(string|Array)=} opt_substitutions An optional set of substitution |
39 * strings corresponding to the "placeholders" attributes in messages.json. | 39 * strings corresponding to the "placeholders" attributes in messages.json. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 break; | 78 break; |
79 } | 79 } |
80 } | 80 } |
81 l10n.localizeElement(element, substitutions, substitutions.length != 0); | 81 l10n.localizeElement(element, substitutions, substitutions.length != 0); |
82 // Localize tool-tips | 82 // Localize tool-tips |
83 // TODO(jamiewalch): Move this logic to the html document. | 83 // TODO(jamiewalch): Move this logic to the html document. |
84 var editButton = document.getElementById('this-host-rename'); | 84 var editButton = document.getElementById('this-host-rename'); |
85 editButton.title = chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_RENAME'); | 85 editButton.title = chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_RENAME'); |
86 } | 86 } |
87 }; | 87 }; |
OLD | NEW |