Index: remoting/webapp/me2mom/l10n.js |
diff --git a/remoting/webapp/me2mom/l10n.js b/remoting/webapp/me2mom/l10n.js |
index ce20602281afddf7a9365df7295bcecfb03703fa..20506dcc5458eca595df8e2aa77029afa1da6ba4 100644 |
--- a/remoting/webapp/me2mom/l10n.js |
+++ b/remoting/webapp/me2mom/l10n.js |
@@ -10,16 +10,32 @@ |
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. |
+ * @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; |
+ } else { |
+ console.error('Missing translation for "' + tag + '":', element); |
+ } |
+ return translation != null; |
+}; |
+ |
+/** |
+ * Localize all tags with the i18n-content attribute. |
+ */ |
l10n.localize = function() { |
var elements = document.querySelectorAll('[i18n-content]'); |
for (var i = 0; i < elements.length; ++i) { |
var element = elements[i]; |
- var tag = element.getAttribute('i18n-content'); |
- var translation = chrome.i18n.getMessage(tag); |
- if (translation) { |
- element.innerText = translation; |
- } else { |
- console.error('Missing translation for "' + tag +'":', element); |
- } |
+ l10n.localizeElement(element); |
} |
-} |
+}; |