summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/local_strings.js
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-16 20:45:22 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-16 20:45:22 +0000
commitce08079cf7f61aa56f11dd502690e4318b1db035 (patch)
tree4d82e0ca5b56bf8dd68df61d9d1f90168f4d4b42 /chrome/browser/resources/local_strings.js
parentd77f5a92acbac46b12cbcc81e90314e701d1c95a (diff)
downloadchromium_src-ce08079cf7f61aa56f11dd502690e4318b1db035.zip
chromium_src-ce08079cf7f61aa56f11dd502690e4318b1db035.tar.gz
chromium_src-ce08079cf7f61aa56f11dd502690e4318b1db035.tar.bz2
Unify LocalStrings.
The main difference is that we are now using $1 - $9 instead of %s. This is more consistent with the C++ code as well. BUG=None TEST=None Review URL: http://codereview.chromium.org/1045003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/local_strings.js')
-rw-r--r--chrome/browser/resources/local_strings.js75
1 files changed, 47 insertions, 28 deletions
diff --git a/chrome/browser/resources/local_strings.js b/chrome/browser/resources/local_strings.js
index caeea36..ecf3f5a 100644
--- a/chrome/browser/resources/local_strings.js
+++ b/chrome/browser/resources/local_strings.js
@@ -1,28 +1,47 @@
-/**
- * The local strings get injected into the page usig a varaible named
- * {@code templateData}. This class provides a simpler interface to access those
- * strings.
- * @constructor
- */
-function LocalStrings() {
-}
-
-/**
- * Gets a localized string by its id.
- * @param {string} s The id of the string we want.
- * @return {string} The localized string.
- */
-LocalStrings.prototype.getString = function(s) {
- return templateData[s] || '';
-};
-
-/**
- * Returns a formatted localized string (where all %s contents are replaced
- * by the second argument).
- * @param {string} s The id of the string we want.
- * @param {string} d The string to include in the formatted string.
- * @return {string} The formatted string.
- */
-LocalStrings.prototype.formatString = function(s, d) {
- return this.getString(s).replace(/%s/, d);
-};
+// Copyright (c) 2009-2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * The local strings get injected into the page usig a variable named
+ * {@code templateData}. This class provides a simpler interface to access those
+ * strings.
+ * @constructor
+ */
+function LocalStrings() {
+}
+
+LocalStrings.prototype = {
+ /**
+ * The template data object.
+ * @type {Object}
+ */
+ templateData: null,
+
+ /**
+ * Gets a localized string by its id.
+ * @param {string} s The ID of the string we want.
+ * @return {string} The localized string.
+ */
+ getString: function(id) {
+ // TODO(arv): We should not rely on a global variable here.
+ return (this.templateData || window.templateData)[id] || '';
+ },
+
+ /**
+ * Returns a formatted localized string where $1 to $9 are replaced by the
+ * second to the tenth argument.
+ * @param {string} id The ID of the string we want.
+ * @param {...string} The extra values to include in the formatted output.
+ * @return {string} The formatted string.
+ */
+ getStringF: function(id, var_args) {
+ var s = this.getString(id);
+ var args = arguments;
+ return s.replace(/\$[$1-9]/g, function(m) {
+ if (m == '$$')
+ return '$';
+ return args[m[1]];
+ });
+ }
+};