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..6b7849926f38251fe47d6c5236613b9893c00963 100644 |
| --- a/ui/webui/resources/js/i18n_behavior.js |
| +++ b/ui/webui/resources/js/i18n_behavior.js |
| @@ -4,17 +4,24 @@ |
| /** |
| * @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: { |
| + /* |
|
Dan Beam
2017/05/22 23:26:12
should be /**
dschuyler
2017/05/22 23:31:42
Done in prior patch (this was the error reported b
|
| + * The language the UI is presented in. Used to signal dynamic language |
| + * change. |
| + * @private |
| + */ |
| + locale: { |
| + type: String, |
| + value: '', |
| + }, |
| + }, |
| + |
| /** |
| * Returns a translated string where $1 to $9 are replaced by the given |
| * values. |
| @@ -60,6 +67,18 @@ var I18nBehavior = { |
| }, |
| /** |
| + * Similar to 'i18n', with updates whenever |language| changes. |
|
stevenjb
2017/05/22 23:07:37
nit: Similar to 'i18n', with an unused |locale| pa
dschuyler
2017/05/22 23:30:17
Done.
|
| + * @param {string} language The UI language used. |
|
stevenjb
2017/05/22 23:07:37
locale ?
dschuyler
2017/05/22 23:30:17
Done.
|
| + * @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)); |
|
dschuyler
2017/05/22 23:30:17
Hmm, I've recently read that splicing |arguments|
stevenjb
2017/05/22 23:37:00
splicing or slicing? I wouldn't think that slice h
dschuyler
2017/05/23 00:03:19
Yep, slicing. Thanks for catching the typo.
|
| + }, |
| + |
| + /** |
| * Returns true if a translation exists for |id|. |
| * @param {string} id |
| * @return {boolean} |
| @@ -67,6 +86,13 @@ var I18nBehavior = { |
| i18nExists: function(id) { |
| return loadTimeData.valueExists(id); |
| }, |
| + |
| + /** |
| + * Called when UI strings change. |
|
stevenjb
2017/05/22 23:07:37
nit: Call this when UI strings may have changed (e
dschuyler
2017/05/22 23:30:17
Changed to something similar, though not exact.
d
|
| + */ |
| + updateLocalizedContent: function() { |
|
Dan Beam
2017/05/22 23:15:56
why shouldn't callers just set this.locale directl
dschuyler
2017/05/22 23:30:17
They sure could. I was trying to separate I18nBeha
|
| + this.locale = loadTimeData.getString('language'); |
| + }, |
| }; |
| /** |