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>2009-05-05 19:54:05 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 19:54:05 +0000
commitde17ab159c33d8a89dcccae69c167c5d4a6cda68 (patch)
treec6912bdfc4af4954cf65ef4ff1f7dfd6c2d5a3e6 /chrome/browser/resources/local_strings.js
parentca936213e4aaff3bc046623161f658100af2d084 (diff)
downloadchromium_src-de17ab159c33d8a89dcccae69c167c5d4a6cda68.zip
chromium_src-de17ab159c33d8a89dcccae69c167c5d4a6cda68.tar.gz
chromium_src-de17ab159c33d8a89dcccae69c167c5d4a6cda68.tar.bz2
Move the shared JS and CSS out of the HTML files and into separate files.
Review URL: http://codereview.chromium.org/99151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/local_strings.js')
-rw-r--r--chrome/browser/resources/local_strings.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/chrome/browser/resources/local_strings.js b/chrome/browser/resources/local_strings.js
new file mode 100644
index 0000000..a7ea225
--- /dev/null
+++ b/chrome/browser/resources/local_strings.js
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+// localStrings:
+/**
+ * We get strings into the page by using JSTemplate to populate some elements
+ * with localized content, then reading the content of those elements into
+ * this global strings object.
+ * @param {Node} node The DOM node containing all our strings.
+ */
+function LocalStrings(node) {
+ this.strings_ = {};
+
+ var children = node.children;
+ for (var i = 0, child; child = children[i]; i++) {
+ var id = child.id;
+ if (id) {
+ this.strings_[id] = child.innerHTML;
+ }
+ }
+}
+
+/**
+ * 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 this.strings_[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);
+}; \ No newline at end of file