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 89e1d8aa4e5a16757b3ab8ee2620b997a5f7b435..bde9bdcb69abce3a262ec12ca3d056dbd013c73c 100644 |
--- a/ui/webui/resources/js/i18n_behavior.js |
+++ b/ui/webui/resources/js/i18n_behavior.js |
@@ -39,6 +39,7 @@ var I18nBehavior = { |
/** |
* Returns a translated string where $1 to $9 are replaced by the given |
* values. Also sanitizes the output to filter out dangerous HTML/JS. |
+ * Use with Polymer bindings that are *not* inner-h-t-m-l. |
* @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. |
@@ -46,22 +47,21 @@ var I18nBehavior = { |
*/ |
i18n: function(id, var_args) { |
var rawString = this.i18nRaw_.apply(this, arguments); |
- var htmlStr = |
- parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML; |
- // TODO(dschuyler): use textContent rather than innerHTML; remove replace(). |
- return htmlStr.replace(' ', '\u00a0'); |
+ return parseHtmlSubset('<b>' + rawString + '</b>').firstChild.textContent; |
}, |
/** |
* Similar to 'i18n', returns a translated, sanitized, substituted string. |
* It receives the string ID and a dictionary containing the substitutions |
- * as well as optional additional allowed tags and attributes. |
+ * as well as optional additional allowed tags and attributes. Use with |
+ * Polymer bindings that are inner-h-t-m-l, for example. |
* @param {string} id The ID of the string to translate. |
- * @param {{substitutions: (Array<string>|undefined), |
- * attrs: (Object<function(Node, string):boolean>|undefined), |
- * tags: (Array<string>|undefined)}} opts |
+ * @param {I18nAdvancedOpts=} opts |
+ * @return {string} |
*/ |
i18nAdvanced: function(id, opts) { |
+ if (typeof opts === 'undefined') |
+ opts = {}; |
Dan Beam
2017/06/08 23:21:41
opts = opts || {};
dschuyler
2017/06/09 00:13:39
Done.
|
var args = [id].concat(opts.substitutions || []); |
var rawString = this.i18nRaw_.apply(this, args); |
return parseHtmlSubset('<b>' + rawString + '</b>', opts.tags, opts.attrs) |
@@ -91,23 +91,31 @@ var I18nBehavior = { |
}, |
/** |
- * Call this when UI strings may have changed. This will send an update to any |
- * data bindings to i18nDynamic(locale, ...). |
+ * Call this when UI strings may have changed. This will send an update to |
+ * any data bindings to i18nDynamic(locale, ...). |
*/ |
i18nUpdateLocale: function() { |
this.locale = loadTimeData.getString('language'); |
}, |
}; |
+/** |
+ * @typedef {{ |
+ * substitutions: (Array<string>|undefined), |
+ * attrs: (Object<function(Node, string):boolean>|undefined), |
+ * tags: (Array<string>|undefined), |
+ * }} |
+ */ |
+var I18nAdvancedOpts; |
+ |
/** |
* TODO(stevenjb): Replace with an interface. b/24294625 |
* @typedef {{ |
- * i18n: function(string, ...string): string}}, |
- * i18nAdvanced: function({ |
- * substitutions: (Array<string>|undefined), |
- * attrs: (Object<function(Node, string):boolean>|undefined), |
- * tags: (Array<string>|undefined)}, opts), |
- * i18nExists: function(string) |
+ * i18n: function(string, ...string): string, |
+ * i18nAdvanced: function(string, I18nAdvancedOpts=): string, |
+ * i18nDynamic: function(string, string, ...string): string, |
+ * i18nExists: function(string), |
+ * i18nUpdateLocale: function() |
* }} |
*/ |
I18nBehavior.Proto; |