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 // TODO(arv): Namespace and share code with DOMUI |
| 6 |
| 7 /** |
| 8 * The local strings get injected into the page usig a varaible named |
| 9 * {@code templateData}. This class provides a simpler interface to access those |
| 10 * strings. |
| 11 * @constructor |
| 12 */ |
| 13 function LocalStrings() { |
| 14 } |
| 15 |
| 16 LocalStrings.prototype = { |
| 17 |
| 18 /** |
| 19 * The template data object. |
| 20 * @type {Object} |
| 21 */ |
| 22 templateData: null, |
| 23 |
| 24 /** |
| 25 * Gets a localized string by its id. |
| 26 * @param {string} s The id of the string we want. |
| 27 * @return {string} The localized string. |
| 28 */ |
| 29 getString: function(id) { |
| 30 return this.templateData[id] || ''; |
| 31 }, |
| 32 |
| 33 /** |
| 34 * Returns a formatted localized string where all %s contents are replaced |
| 35 * by the second argument and where $1 to $9 are replaced by the second to |
| 36 * tenths arguments. |
| 37 * @param {string} id The ID of the string we want. |
| 38 * @param {string} v The string to include in the formatted string. |
| 39 * @param {...string} The extra values to include in the fomatted output. |
| 40 * @return {string} The formatted string. |
| 41 */ |
| 42 getStringF: function(id, v, var_args) { |
| 43 // The localized messages should contain $n but they also use %s from time |
| 44 // to time so we support both until all the messages have been unified. |
| 45 var s = this.getString(id); |
| 46 var args = arguments; |
| 47 return s.replace(/%s|\$[$1-9]/g, function(m) { |
| 48 if (m == '%s') |
| 49 return v; |
| 50 if (m == '$$') |
| 51 return '$'; |
| 52 return args[m[1]]; |
| 53 }); |
| 54 } |
| 55 }; |
OLD | NEW |