Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: ui/webui/resources/js/i18n_behavior.js

Issue 2938483002: [MD settings] use regex to replace all nbsp (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/i18n_behavior_test.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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('&nbsp;', '\u00a0'); 46 return htmlStr.replace(/&nbsp;/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
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;
OLDNEW
« no previous file with comments | « chrome/test/data/webui/i18n_behavior_test.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698