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

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

Issue 1920253002: Refactors parse_html_subset() into i18n_behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
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 values in
20 * |opt_values|.
19 * @param {string} id The ID of the string to translate. 21 * @param {string} id The ID of the string to translate.
20 * @param {...string} var_args Placeholders required by the string ($0-9). 22 * @param {!Array<string>=} opt_values Optional values to replace the
23 * placeholders $1 to $9 in the string.
21 * @return {string} A translated, substituted string. 24 * @return {string} A translated, substituted string.
22 */ 25 */
23 i18n: function(id, var_args) { 26 i18nNoSanitizeHtml: function(id, opt_values) {
24 return arguments.length == 1 ? loadTimeData.getString(id) : 27 if (opt_values) {
25 loadTimeData.getStringF.apply(loadTimeData, arguments); 28 opt_values.unshift(id);
Dan Beam 2016/04/27 02:38:27 don't do this, opt_values is passed by reference a
Moe 2016/04/27 15:08:46 yep. this is pretty dumb.
29 return loadTimeData.getStringF.apply(loadTimeData, opt_values);
30 } else {
31 return loadTimeData.getString(id);
32 }
33 },
34
35 /**
36 * Returns a translated string where $1 to $9 are replaced by values in
37 * |opt_values|. Also sanitizes the output to filter out dangerous HTML/JS.
38 * @param {string} id The ID of the string to translate.
39 * @param {!Array<string>=} opt_values Optional values to replace the
40 * placeholders $1 to $9 in the string.
41 * @param {Array<string>=} opt_extraTags Optional extra allowed tags.
42 * @param {Object<function(Node, string):boolean>=} opt_extraAttrs
43 * Optional extra allowed attributes (all tags are run through these).
44 * @return {string} A translated, sanitized, substituted string.
45 */
46 i18n: function(id, opt_values, opt_extraTags, opt_extraAttrs) {
47 var string = this.i18nNoSanitizeHtml(id, opt_values);
48 var docFrag = parseHtmlSubset('<b>' + string + '</b>',
49 opt_extraTags,
50 opt_extraAttrs);
51 return docFrag.firstChild.innerHTML;
26 }, 52 },
Dan Beam 2016/04/27 02:38:27 i don't really understand what you're doing here,
Moe 2016/04/27 15:08:46 This code is doing exactly that (the new function
27 }; 53 };
OLDNEW
« no previous file with comments | « ui/webui/resources/js/compiled_resources2.gyp ('k') | ui/webui/resources/js/parse_html_subset.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698