OLD | NEW |
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2011 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. |
(...skipping 26 matching lines...) Expand all Loading... |
37 return l10n.localizeElementFromTag(element, tag, opt_substitutions); | 37 return l10n.localizeElementFromTag(element, tag, opt_substitutions); |
38 }; | 38 }; |
39 | 39 |
40 /** | 40 /** |
41 * Localize all tags with the i18n-content attribute, using i18n-data-n | 41 * Localize all tags with the i18n-content attribute, using i18n-data-n |
42 * attributes to specify any placeholder substitutions. | 42 * attributes to specify any placeholder substitutions. |
43 */ | 43 */ |
44 l10n.localize = function() { | 44 l10n.localize = function() { |
45 var elements = document.querySelectorAll('[i18n-content]'); | 45 var elements = document.querySelectorAll('[i18n-content]'); |
46 for (var i = 0; i < elements.length; ++i) { | 46 for (var i = 0; i < elements.length; ++i) { |
47 var element = elements[i]; | 47 /** @type {Element} */ var element = elements[i]; |
48 var substitutions = null; | 48 var substitutions = null; |
49 for (var j = 1; j < 9; ++j) { | 49 for (var j = 1; j < 9; ++j) { |
50 var attr = 'i18n-value-' + j; | 50 var attr = 'i18n-value-' + j; |
51 if (element.hasAttribute(attr)) { | 51 if (element.hasAttribute(attr)) { |
52 if (!substitutions) { | 52 if (!substitutions) { |
53 substitutions = []; | 53 substitutions = []; |
54 } | 54 } |
55 substitutions.push(element.getAttribute(attr)); | 55 substitutions.push(element.getAttribute(attr)); |
56 } else { | 56 } else { |
57 break; | 57 break; |
58 } | 58 } |
59 } | 59 } |
60 l10n.localizeElement(element, substitutions); | 60 l10n.localizeElement(element, substitutions); |
61 } | 61 } |
62 }; | 62 }; |
OLD | NEW |