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 931f8c8f029ecead1ea15335e378ca8a47ccbe1b..94704db51d7a7f1b0787250b7f32d4f270cf5ff0 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,20 @@ 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(/ /g, '\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) { |
+ opts = opts || {}; |
var args = [id].concat(opts.substitutions || []); |
var rawString = this.i18nRaw_.apply(this, args); |
return parseHtmlSubset('<b>' + rawString + '</b>', opts.tags, opts.attrs) |
@@ -91,23 +90,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; |