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

Unified Diff: ui/webui/resources/js/i18n_behavior.js

Issue 2886843005: [i18n] use Polymer data binding to change locale strings (Closed)
Patch Set: closure fix Created 3 years, 7 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
« no previous file with comments | « chrome/browser/resources/chromeos/login/oobe_welcome.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/i18n_behavior.js
diff --git a/ui/webui/resources/js/i18n_behavior.js b/ui/webui/resources/js/i18n_behavior.js
index 05c9cf6567893662be14784bc12903e22dd967e6..9c1918f70f4054d6defc8c47b357dafbce1e180a 100644
--- a/ui/webui/resources/js/i18n_behavior.js
+++ b/ui/webui/resources/js/i18n_behavior.js
@@ -4,17 +4,23 @@
/**
* @fileoverview
- * 'I18nBehavior' is a behavior to mix in loading of
- * internationalization strings.
- *
- * Example:
- * behaviors: [
- * I18nBehavior,
- * ],
+ * 'I18nBehavior' is a behavior to mix in loading of internationalization
+ * strings.
*/
/** @polymerBehavior */
var I18nBehavior = {
+ properties: {
+ /**
+ * The language the UI is presented in. Used to signal dynamic language
+ * change.
+ */
+ locale: {
+ type: String,
+ value: '',
+ },
+ },
+
/**
* Returns a translated string where $1 to $9 are replaced by the given
* values.
@@ -60,6 +66,19 @@ var I18nBehavior = {
},
/**
+ * Similar to 'i18n', with an unused |locale| parameter used to trigger
+ * updates when |this.locale| changes.
+ * @param {string} locale The UI language used.
+ * @param {string} id The ID of the string to translate.
+ * @param {...string} var_args Values to replace the placeholders $1 to $9
+ * in the string.
+ * @return {string} A translated, sanitized, substituted string.
+ */
+ i18nDynamic: function(language, id, var_args) {
+ return this.i18n.apply(this, Array.prototype.slice.call(arguments, 1));
Dan Beam 2017/05/22 23:39:02 i think this slice here is fine
dschuyler 2017/05/23 00:03:19 Acknowledged.
+ },
+
+ /**
* Returns true if a translation exists for |id|.
* @param {string} id
* @return {boolean}
@@ -67,6 +86,15 @@ var I18nBehavior = {
i18nExists: function(id) {
return loadTimeData.valueExists(id);
},
+
+ /**
+ * Call this when UI strings may have changed (e.g. because the locale
+ * changed). This will send an update to any data bindings to
+ * i18nDynamic(locale, ...).
+ */
+ updateLocalizedContent: function() {
+ this.locale = loadTimeData.getString('language');
+ },
};
/**
« no previous file with comments | « chrome/browser/resources/chromeos/login/oobe_welcome.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698