| 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 | 7 * 'I18nBehavior' is a behavior to mix in loading of |
| 8 * internationalization strings. | 8 * internationalization strings. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 * @param {string} id The ID of the string to translate. | 36 * @param {string} id The ID of the string to translate. |
| 37 * @param {...string} var_args Values to replace the placeholders $1 to $9 | 37 * @param {...string} var_args Values to replace the placeholders $1 to $9 |
| 38 * in the string. | 38 * in the string. |
| 39 * @return {string} A translated, sanitized, substituted string. | 39 * @return {string} A translated, sanitized, substituted string. |
| 40 */ | 40 */ |
| 41 i18n: function(id, var_args) { | 41 i18n: function(id, var_args) { |
| 42 var rawString = this.i18nRaw_.apply(this, arguments); | 42 var rawString = this.i18nRaw_.apply(this, arguments); |
| 43 var htmlStr = | 43 var htmlStr = |
| 44 parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML; | 44 parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML; |
| 45 // TODO(dschuyler): use textContent rather than innerHTML; remove replace(). | 45 // TODO(dschuyler): use textContent rather than innerHTML; remove replace(). |
| 46 return htmlStr.replace(' ', '\u00a0'); | 46 return htmlStr.replace(/ /g, '\u00a0'); |
| 47 }, | 47 }, |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Similar to 'i18n', returns a translated, sanitized, substituted string. | 50 * Similar to 'i18n', returns a translated, sanitized, substituted string. |
| 51 * It receives the string ID and a dictionary containing the substitutions | 51 * It receives the string ID and a dictionary containing the substitutions |
| 52 * as well as optional additional allowed tags and attributes. | 52 * as well as optional additional allowed tags and attributes. |
| 53 * @param {string} id The ID of the string to translate. | 53 * @param {string} id The ID of the string to translate. |
| 54 * @param {{substitutions: (Array<string>|undefined), | 54 * @param {{substitutions: (Array<string>|undefined), |
| 55 * attrs: (Object<function(Node, string):boolean>|undefined), | 55 * attrs: (Object<function(Node, string):boolean>|undefined), |
| 56 * tags: (Array<string>|undefined)}} opts | 56 * tags: (Array<string>|undefined)}} opts |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 * @typedef {{ | 77 * @typedef {{ |
| 78 * i18n: function(string, ...string): string}}, | 78 * i18n: function(string, ...string): string}}, |
| 79 * i18nAdvanced: function({ | 79 * i18nAdvanced: function({ |
| 80 * substitutions: (Array<string>|undefined), | 80 * substitutions: (Array<string>|undefined), |
| 81 * attrs: (Object<function(Node, string):boolean>|undefined), | 81 * attrs: (Object<function(Node, string):boolean>|undefined), |
| 82 * tags: (Array<string>|undefined)}, opts), | 82 * tags: (Array<string>|undefined)}, opts), |
| 83 * i18nExists: function(string) | 83 * i18nExists: function(string) |
| 84 * }} | 84 * }} |
| 85 */ | 85 */ |
| 86 I18nBehavior.Proto; | 86 I18nBehavior.Proto; |
| OLD | NEW |