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

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

Issue 405743002: Typecheck some of ui/webui/resources/js/ with Closure compiler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done for tonight Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * NOTE: The use of this file is deprecated. Use load_time_data.js instead. 6 * NOTE: The use of this file is deprecated. Use load_time_data.js instead.
7 * 7 *
8 * The local strings get injected into the page using a variable named 8 * The local strings get injected into the page using a variable named
9 * {@code templateData}. This class provides a simpler interface to access those 9 * {@code templateData}. This class provides a simpler interface to access those
10 * strings. 10 * strings.
11 * 11 *
12 * @param {Object} opt_templateData Optional object containing translated 12 * @param {Object=} opt_templateData Optional object containing translated
arv (Not doing code reviews) 2014/07/24 16:44:24 No need to include "Optional" in the description s
Dan Beam 2014/07/25 01:52:33 Done.
13 * strings. If this is not supplied during construction, it can be 13 * strings. If this is not supplied during construction, it can be
14 * assigned to the templateData property after construction. If all else 14 * assigned to the templateData property after construction. If all else
15 * fails, the value of window.templateDate will be used. 15 * fails, the value of window.templateDate will be used.
16 * @constructor 16 * @constructor
17 */ 17 */
18 function LocalStrings(opt_templateData) { 18 function LocalStrings(opt_templateData) {
19 this.templateData = opt_templateData; 19 this.templateData = opt_templateData;
20 } 20 }
21 21
22 // Start of anonymous namespace. 22 // Start of anonymous namespace.
23 (function() { 23 (function() {
24 24
25 /** 25 /**
26 * Returns a formatted string where $1 to $9 are replaced by the second to the 26 * Returns a formatted string where $1 to $9 are replaced by the second to the
27 * tenth argument. 27 * tenth argument.
28 * @param {string} s The format string. 28 * @param {string} s The format string.
29 * @param {...string} The extra values to include in the formatted output. 29 * @param {Arguments} args The extra values to include in the formatted
30 * output.
30 * @return {string} The string after format substitution. 31 * @return {string} The string after format substitution.
31 */ 32 */
32 function replaceArgs(s, args) { 33 function replaceArgs(s, args) {
33 return s.replace(/\$[$1-9]/g, function(m) { 34 return s.replace(/\$[$1-9]/g, function(m) {
34 return (m == '$$') ? '$' : args[m[1]]; 35 return (m == '$$') ? '$' : args[m[1]];
35 }); 36 });
36 } 37 }
37 38
38 /** 39 /**
39 * Returns a string after removing Windows-style accelerators. 40 * Returns a string after removing Windows-style accelerators.
40 * @param {string} s The input string that may contain accelerators. 41 * @param {string} s The input string that may contain accelerators.
41 * @return {string} The resulting string with accelerators removed. 42 * @return {string} The resulting string with accelerators removed.
42 */ 43 */
43 function trimAccelerators(s) { 44 function trimAccelerators(s) {
44 return s.replace(/&{1,2}/g, function(m) { 45 return s.replace(/&{1,2}/g, function(m) {
45 return (m == '&&') ? '&' : ''; 46 return (m == '&&') ? '&' : '';
46 }); 47 });
47 } 48 }
48 49
49 LocalStrings.prototype = { 50 LocalStrings.prototype = {
50 /** 51 /**
51 * The template data object. 52 * The template data object.
52 * @type {Object} 53 * @type {Object|undefined}
53 */ 54 */
54 templateData: null, 55 templateData: undefined,
55 56
56 /** 57 /**
57 * Gets a localized string by its id. 58 * Gets a localized string by its id.
58 * @param {string} s The ID of the string we want. 59 * @param {string} id The ID of the string we want.
59 * @return {string} The localized string. 60 * @return {string} The localized string.
60 */ 61 */
61 getString: function(id) { 62 getString: function(id) {
62 // TODO(arv): We should not rely on a global variable here. 63 // TODO(arv): We should not rely on a global variable here.
63 var templateData = this.templateData || window.templateData; 64 var templateData = this.templateData || window.templateData;
64 var str = templateData[id]; 65 var str = templateData[id];
65 // TODO(jhawkins): Change to console.error when all errors are fixed. 66 // TODO(jhawkins): Change to console.error when all errors are fixed.
66 if (!str) 67 if (!str)
67 console.warn('Missing string for id: ' + id); 68 console.warn('Missing string for id: ' + id);
68 return str; 69 return str;
69 }, 70 },
70 71
71 /** 72 /**
72 * Returns a formatted localized string where $1 to $9 are replaced by the 73 * Returns a formatted localized string where $1 to $9 are replaced by the
73 * second to the tenth argument. 74 * second to the tenth argument.
74 * @param {string} id The ID of the string we want. 75 * @param {string} id The ID of the string we want.
75 * @param {...string} The extra values to include in the formatted output. 76 * @param {...string} var_args The extra values to include in the formatted
77 * output.
76 * @return {string} The formatted string. 78 * @return {string} The formatted string.
77 */ 79 */
78 getStringF: function(id, var_args) { 80 getStringF: function(id, var_args) {
79 return replaceArgs(this.getString(id), arguments); 81 return replaceArgs(this.getString(id), arguments);
80 }, 82 },
81 }; 83 };
82 84
83 // End of anonymous namespace. 85 // End of anonymous namespace.
84 })(); 86 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698