summaryrefslogtreecommitdiffstats
path: root/chrome/browser
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
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')
-rw-r--r--chrome/browser/dom_ui/downloads_ui.cc2
-rw-r--r--chrome/browser/resources/downloads.html8
-rw-r--r--chrome/browser/resources/history.html2
-rw-r--r--chrome/browser/resources/local_strings.js75
-rw-r--r--chrome/browser/resources/new_new_tab.js2
5 files changed, 54 insertions, 35 deletions
diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc
index a7ae595..9b45034 100644
--- a/chrome/browser/dom_ui/downloads_ui.cc
+++ b/chrome/browser/dom_ui/downloads_ui.cc
@@ -77,7 +77,7 @@ void DownloadsUIHTMLSource::StartDataRequest(const std::string& path,
// Dangerous file.
localized_strings.SetString(L"danger_desc",
- l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, L"%s"));
+ l10n_util::GetString(IDS_PROMPT_DANGEROUS_DOWNLOAD));
localized_strings.SetString(L"danger_save",
l10n_util::GetString(IDS_SAVE_DOWNLOAD));
localized_strings.SetString(L"danger_discard",
diff --git a/chrome/browser/resources/downloads.html b/chrome/browser/resources/downloads.html
index 79e76ef..3f30f5f 100644
--- a/chrome/browser/resources/downloads.html
+++ b/chrome/browser/resources/downloads.html
@@ -265,8 +265,8 @@ Downloads.prototype.setSearchText = function(searchText) {
*/
Downloads.prototype.updateSummary = function() {
if (this.searchText_) {
- this.summary_.textContent = localStrings.formatString(
- 'searchresultsfor', this.searchText_);
+ this.summary_.textContent = localStrings.getStringF('searchresultsfor',
+ this.searchText_);
} else {
this.summary_.innerHTML = localStrings.getString('downloads');
}
@@ -478,8 +478,8 @@ Download.prototype.update = function(download) {
this.received_ = download.received;
if (this.state_ == Download.States.DANGEROUS) {
- this.dangerDesc_.innerHTML = localStrings.formatString('danger_desc',
- this.fileName_);
+ this.dangerDesc_.innerHTML = localStrings.getStringF('danger_desc',
+ this.fileName_);
this.danger_.style.display = 'block';
this.safe_.style.display = 'none';
} else {
diff --git a/chrome/browser/resources/history.html b/chrome/browser/resources/history.html
index 3c37380..c5d2006 100644
--- a/chrome/browser/resources/history.html
+++ b/chrome/browser/resources/history.html
@@ -617,7 +617,7 @@ HistoryView.prototype.displayResults_ = function() {
HistoryView.prototype.displaySummaryBar_ = function() {
var searchText = this.model_.getSearchText();
if (searchText != '') {
- this.summaryTd_.textContent = localStrings.formatString('searchresultsfor',
+ this.summaryTd_.textContent = localStrings.getStringF('searchresultsfor',
searchText);
} else {
this.summaryTd_.innerHTML = localStrings.getString('history');
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]];
+ });
+ }
+};
diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js
index cac3e70..6a741fe7 100644
--- a/chrome/browser/resources/new_new_tab.js
+++ b/chrome/browser/resources/new_new_tab.js
@@ -700,7 +700,7 @@ function syncAlreadyEnabled(message) {
function formatTabsText(numTabs) {
if (numTabs == 1)
return localStrings.getString('closedwindowsingle');
- return localStrings.formatString('closedwindowmultiple', numTabs);
+ return localStrings.getStringF('closedwindowmultiple', numTabs);
}
/**