Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ext/common.js

Issue 29376555: [adblockplus] Issue 4915 - Expose ext.i18n for background pages (Closed)
Patch Set: Removed I18n class Created March 2, 2017, 5:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/common.js
diff --git a/ext/common.js b/ext/common.js
index c00cfffac710285aeef7b16823cd952067c7ea4c..ae0a12ca9a466bcd1424d37759ca6181a920264f 100644
--- a/ext/common.js
+++ b/ext/common.js
@@ -17,6 +17,10 @@
(function(global)
{
+ const Cu = Components.utils;
+
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
if (!global.ext)
global.ext = {};
@@ -82,6 +86,30 @@
}
};
+ let pageName = "global";
+ if (typeof location !== "undefined")
+ pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, "");
+
+ let stringBundle = Services.strings.createBundle(
+ "chrome://adblockplus/locale/" + pageName + ".properties?" + Math.random());
+
+ global.ext.i18n = {
+ getMessage(key, args)
+ {
+ try {
+ return stringBundle.GetStringFromName(key);
+ }
+ catch(e)
+ {
+ // Don't report errors for special strings, these are expected to be
+ // missing.
+ if (key[0] != "@")
+ Cu.reportError(e);
+ return "";
+ }
+ }
+ };
+
if (typeof exports == "object")
exports = global.ext;
})(this);
« no previous file with comments | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld