Chromium Code Reviews| 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. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 * Because we use i18n-value attributes to implement translations of rich | 54 * Because we use i18n-value attributes to implement translations of rich |
| 55 * content (including paragraphs with hyperlinks), we localize these as | 55 * content (including paragraphs with hyperlinks), we localize these as |
| 56 * HTML iff there are any substitutions. | 56 * HTML iff there are any substitutions. |
| 57 */ | 57 */ |
| 58 l10n.localize = function() { | 58 l10n.localize = function() { |
| 59 var elements = document.querySelectorAll('[i18n-content]'); | 59 var elements = document.querySelectorAll('[i18n-content]'); |
| 60 for (var i = 0; i < elements.length; ++i) { | 60 for (var i = 0; i < elements.length; ++i) { |
| 61 /** @type {Element} */ var element = elements[i]; | 61 /** @type {Element} */ var element = elements[i]; |
| 62 var substitutions = null; | 62 var substitutions = null; |
| 63 for (var j = 1; j < 9; ++j) { | 63 for (var j = 1; j < 9; ++j) { |
| 64 var attr = 'i18n-value-' + j; | 64 var value = 'i18n-value-' + j; |
| 65 if (element.hasAttribute(attr)) { | 65 var valueName = 'i18n-value-name-' + j; |
| 66 if (element.hasAttribute(value) || element.hasAttribute(valueName)) { | |
| 66 if (!substitutions) { | 67 if (!substitutions) { |
| 67 substitutions = []; | 68 substitutions = []; |
|
Wez
2012/06/28 23:00:20
Why do you do this? Can't you initialize substitut
Jamie
2012/06/28 23:28:57
Done.
| |
| 68 } | 69 } |
| 69 substitutions.push(element.getAttribute(attr)); | 70 if (element.hasAttribute(value)) { |
| 71 substitutions.push(element.getAttribute(value)); | |
| 72 } else { | |
| 73 var name = element.getAttribute(valueName); | |
| 74 var translation = chrome.i18n.getMessage(name); | |
| 75 if (translation) { | |
| 76 substitutions.push(translation); | |
| 77 } else { | |
| 78 console.error('Missing translation for substitution: ' + name); | |
| 79 substitutions.push(name); | |
| 80 } | |
| 81 } | |
| 70 } else { | 82 } else { |
| 71 break; | 83 break; |
| 72 } | 84 } |
| 73 } | 85 } |
| 74 l10n.localizeElement(element, substitutions, !!substitutions); | 86 l10n.localizeElement(element, substitutions, !!substitutions); |
| 75 // Localize tool-tips | 87 // Localize tool-tips |
| 76 // TODO(jamiewalch): Move this logic to the html document. | 88 // TODO(jamiewalch): Move this logic to the html document. |
| 77 var editButton = document.getElementById('this-host-rename'); | 89 var editButton = document.getElementById('this-host-rename'); |
| 78 editButton.title = chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_RENAME'); | 90 editButton.title = chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_RENAME'); |
| 79 } | 91 } |
| 80 }; | 92 }; |
| OLD | NEW |