Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1841)

Unified Diff: remoting/webapp/me2mom/l10n.js

Issue 7547001: Propagate connected user to web app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
-}
+};

Powered by Google App Engine
This is Rietveld 408576698