| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * The local strings get injected into the page usig a variable named | |
| 7 * {@code templateData}. This class provides a simpler interface to access those | |
| 8 * strings. | |
| 9 * @constructor | |
| 10 */ | |
| 11 function LocalStrings() { | |
| 12 } | |
| 13 | |
| 14 LocalStrings.prototype = { | |
| 15 /** | |
| 16 * The template data object. | |
| 17 * @type {Object} | |
| 18 */ | |
| 19 templateData: null, | |
| 20 | |
| 21 /** | |
| 22 * Gets a localized string by its id. | |
| 23 * @param {string} s The ID of the string we want. | |
| 24 * @return {string} The localized string. | |
| 25 */ | |
| 26 getString: function(id) { | |
| 27 // TODO(arv): We should not rely on a global variable here. | |
| 28 return (this.templateData || window.templateData)[id] || ''; | |
| 29 }, | |
| 30 | |
| 31 /** | |
| 32 * Returns a formatted localized string where $1 to $9 are replaced by the | |
| 33 * second to the tenth argument. | |
| 34 * @param {string} id The ID of the string we want. | |
| 35 * @param {...string} The extra values to include in the formatted output. | |
| 36 * @return {string} The formatted string. | |
| 37 */ | |
| 38 getStringF: function(id, var_args) { | |
| 39 var s = this.getString(id); | |
| 40 var args = arguments; | |
| 41 return s.replace(/\$[$1-9]/g, function(m) { | |
| 42 if (m == '$$') | |
| 43 return '$'; | |
| 44 return args[m[1]]; | |
| 45 }); | |
| 46 } | |
| 47 }; | |
| OLD | NEW |