Chromium Code Reviews| 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'); |
| + }, |
| }; |
| /** |