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

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

Issue 1952253004: I18nBehavior: make i18nRaw private as raw_, add tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i18n-behavior
Patch Set: . Created 4 years, 7 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/webui_resource_browsertest.cc ('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:
11 * behaviors: [ 11 * behaviors: [
12 * I18nBehavior, 12 * I18nBehavior,
13 * ], 13 * ],
14 */ 14 */
15 15
16 /** @polymerBehavior */ 16 /** @polymerBehavior */
17 var I18nBehavior = { 17 var I18nBehavior = {
18 /** 18 /**
19 * Returns a translated string where $1 to $9 are replaced by the given 19 * Returns a translated string where $1 to $9 are replaced by the given
20 * values. 20 * values.
21 * @param {string} id The ID of the string to translate. 21 * @param {string} id The ID of the string to translate.
22 * @param {...string} var_args Values to replace the placeholders $1 to $9 22 * @param {...string} var_args Values to replace the placeholders $1 to $9
23 * in the string. 23 * in the string.
24 * @return {string} A translated, substituted string. 24 * @return {string} A translated, substituted string.
25 * @private
25 */ 26 */
26 i18nRaw: function(id, var_args) { 27 i18nRaw_: function(id, var_args) {
27 return arguments.length == 1 ? loadTimeData.getString(id) : 28 return arguments.length == 1 ? loadTimeData.getString(id) :
28 loadTimeData.getStringF.apply(loadTimeData, arguments); 29 loadTimeData.getStringF.apply(loadTimeData, arguments);
29 }, 30 },
30 31
31 /** 32 /**
32 * Returns a translated string where $1 to $9 are replaced by the given 33 * Returns a translated string where $1 to $9 are replaced by the given
33 * values. Also sanitizes the output to filter out dangerous HTML/JS. 34 * values. Also sanitizes the output to filter out dangerous HTML/JS.
34 * @param {string} id The ID of the string to translate. 35 * @param {string} id The ID of the string to translate.
35 * @param {...string} var_args Values to replace the placeholders $1 to $9 36 * @param {...string} var_args Values to replace the placeholders $1 to $9
36 * in the string. 37 * in the string.
37 * @return {string} A translated, sanitized, substituted string. 38 * @return {string} A translated, sanitized, substituted string.
38 */ 39 */
39 i18n: function(id, var_args) { 40 i18n: function(id, var_args) {
40 var rawString = this.i18nRaw.apply(this, arguments); 41 var rawString = this.i18nRaw_.apply(this, arguments);
41 return parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML; 42 return parseHtmlSubset('<b>' + rawString + '</b>').firstChild.innerHTML;
42 }, 43 },
43 44
44 /** 45 /**
45 * Similar to 'i18n', returns a translated, sanitized, substituted string. 46 * Similar to 'i18n', returns a translated, sanitized, substituted string.
46 * It receives the string ID and a dictionary containing the substitutions 47 * It receives the string ID and a dictionary containing the substitutions
47 * as well as optional additional allowed tags and attributes. 48 * as well as optional additional allowed tags and attributes.
48 * @param {string} id The ID of the string to translate. 49 * @param {string} id The ID of the string to translate.
49 * @param {{substitutions: (Array<string>|undefined), 50 * @param {{substitutions: (Array<string>|undefined),
50 * attrs: (Object<function(Node, string):boolean>|undefined), 51 * attrs: (Object<function(Node, string):boolean>|undefined),
51 * tags: (Array<string>|undefined)}} opts 52 * tags: (Array<string>|undefined)}} opts
52 */ 53 */
53 i18nAdvanced: function(id, opts) { 54 i18nAdvanced: function(id, opts) {
54 var args = [id].concat(opts.substitutions || []); 55 var args = [id].concat(opts.substitutions || []);
55 var rawString = this.i18nRaw.apply(this, args); 56 var rawString = this.i18nRaw_.apply(this, args);
56 return parseHtmlSubset('<b>' + rawString + '</b>', opts.tags, opts.attrs) 57 return parseHtmlSubset('<b>' + rawString + '</b>', opts.tags, opts.attrs)
57 .firstChild.innerHTML; 58 .firstChild.innerHTML;
58 } 59 },
59 }; 60 };
OLDNEW
« no previous file with comments | « chrome/test/data/webui/webui_resource_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698