| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'I18nBehavior' is a behavior to mix in loading of internationalization | 7 * 'I18nBehavior' is a behavior to mix in loading of internationalization |
| 8 * strings. | 8 * strings. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 /** | 39 /** |
| 40 * Returns a translated string where $1 to $9 are replaced by the given | 40 * Returns a translated string where $1 to $9 are replaced by the given |
| 41 * values. Also sanitizes the output to filter out dangerous HTML/JS. | 41 * values. Also sanitizes the output to filter out dangerous HTML/JS. |
| 42 * @param {string} id The ID of the string to translate. | 42 * @param {string} id The ID of the string to translate. |
| 43 * @param {...string} var_args Values to replace the placeholders $1 to $9 | 43 * @param {...string} var_args Values to replace the placeholders $1 to $9 |
| 44 * in the string. | 44 * in the string. |
| 45 * @return {string} A translated, sanitized, substituted string. | 45 * @return {string} A translated, sanitized, substituted string. |
| 46 */ | 46 */ |
| 47 i18n: function(id, var_args) { | 47 i18n: function(id, var_args) { |
| 48 var rawString = this.i18nRaw_.apply(this, arguments); | 48 var rawString = this.i18nRaw_.apply(this, arguments); |
| 49 return parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML; | 49 var htmlStr = |
| 50 parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML; |
| 51 // TODO(dschuyler): use textContent rather than innerHTML; remove replace(). |
| 52 return htmlStr.replace(' ', '\u00a0'); |
| 50 }, | 53 }, |
| 51 | 54 |
| 52 /** | 55 /** |
| 53 * Similar to 'i18n', returns a translated, sanitized, substituted string. | 56 * Similar to 'i18n', returns a translated, sanitized, substituted string. |
| 54 * It receives the string ID and a dictionary containing the substitutions | 57 * It receives the string ID and a dictionary containing the substitutions |
| 55 * as well as optional additional allowed tags and attributes. | 58 * as well as optional additional allowed tags and attributes. |
| 56 * @param {string} id The ID of the string to translate. | 59 * @param {string} id The ID of the string to translate. |
| 57 * @param {{substitutions: (Array<string>|undefined), | 60 * @param {{substitutions: (Array<string>|undefined), |
| 58 * attrs: (Object<function(Node, string):boolean>|undefined), | 61 * attrs: (Object<function(Node, string):boolean>|undefined), |
| 59 * tags: (Array<string>|undefined)}} opts | 62 * tags: (Array<string>|undefined)}} opts |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 * @typedef {{ | 104 * @typedef {{ |
| 102 * i18n: function(string, ...string): string}}, | 105 * i18n: function(string, ...string): string}}, |
| 103 * i18nAdvanced: function({ | 106 * i18nAdvanced: function({ |
| 104 * substitutions: (Array<string>|undefined), | 107 * substitutions: (Array<string>|undefined), |
| 105 * attrs: (Object<function(Node, string):boolean>|undefined), | 108 * attrs: (Object<function(Node, string):boolean>|undefined), |
| 106 * tags: (Array<string>|undefined)}, opts), | 109 * tags: (Array<string>|undefined)}, opts), |
| 107 * i18nExists: function(string) | 110 * i18nExists: function(string) |
| 108 * }} | 111 * }} |
| 109 */ | 112 */ |
| 110 I18nBehavior.Proto; | 113 I18nBehavior.Proto; |
| OLD | NEW |