summaryrefslogtreecommitdiffstats
path: root/remoting/webapp/me2mom/l10n.js
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/webapp/me2mom/l10n.js')
-rw-r--r--remoting/webapp/me2mom/l10n.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/remoting/webapp/me2mom/l10n.js b/remoting/webapp/me2mom/l10n.js
index 409feed..d504f90 100644
--- a/remoting/webapp/me2mom/l10n.js
+++ b/remoting/webapp/me2mom/l10n.js
@@ -9,15 +9,15 @@ var l10n = l10n || {};
* Localize an element by setting its innerText according to its i18n-content
* attribute, and an optional set of substitutions.
* @param {Element} element The element to localize.
- * @param {string=} opt_substitutions An optional set of substitution strings
- * corresponding to the "placeholders"attributes in messages.json.
+ * @param {{string|Object}=} opt_substitutions An optional set of substitution
+ * strings corresponding to the "placeholders" attributes in messages.json.
* @return {boolean} True if the localization was successful; false otherwise.
*/
l10n.localizeElement = function(element, opt_substitutions) {
var tag = element.getAttribute('i18n-content');
var translation = chrome.i18n.getMessage(tag, opt_substitutions);
if (translation) {
- element.innerText = translation;
+ element.innerHTML = translation;
} else {
console.error('Missing translation for "' + tag + '":', element);
}
@@ -25,12 +25,25 @@ l10n.localizeElement = function(element, opt_substitutions) {
};
/**
- * Localize all tags with the i18n-content attribute.
+ * Localize all tags with the i18n-content attribute, using i18n-data-n
+ * attributes to specify any placeholder substitutions.
*/
l10n.localize = function() {
var elements = document.querySelectorAll('[i18n-content]');
for (var i = 0; i < elements.length; ++i) {
var element = elements[i];
- l10n.localizeElement(element);
+ var substitutions = null;
+ for (var j = 1; j < 9; ++j) {
+ var attr = 'i18n-value-' + j;
+ if (element.hasAttribute(attr)) {
+ if (!substitutions) {
+ substitutions = [];
+ }
+ substitutions.push(element.getAttribute(attr));
+ } else {
+ break;
+ }
+ }
+ l10n.localizeElement(element, substitutions);
}
};