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 obsolete code addressed review comments Created March 1, 2017, 2:45 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..f15ec52b616328292e4618691bb784b31d41d3fa 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,36 @@
}
};
+ let I18n = global.ext._I18n = function(pageName)
Wladimir Palant 2017/03/02 11:20:20 Any reason why _I18n needs to be exported? IMHO th
wspee 2017/03/02 17:13:29 Done, I thought bundling the state with that logic
+ {
+ // Randomize URI to work around bug 719376
+ this.stringBundle = Services.strings.createBundle(
+ "chrome://adblockplus/locale/" + pageName + ".properties?" + Math.random());
+ };
+
+ I18n.prototype = {
+ getMessage(key)
+ {
+ try {
+ return this.stringBundle.GetStringFromName(key);
Wladimir Palant 2017/03/02 11:20:20 Why did you remove placeholders support? While we
wspee 2017/03/02 17:13:29 Because it didn't work, getI18nMessage never retur
Wladimir Palant 2017/03/06 08:36:40 I see the issue now. I agree, making placeholders
+ }
+ catch(e)
+ {
+ // Don't report errors for special strings, these are expected to be
+ // missing.
+ if (key[0] != "@")
+ Cu.reportError(e);
+ return "";
+ }
+ }
+ }
+
+ let pageName = "global";
+ if (typeof location !== "undefined")
+ pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, "");
+
+ global.ext.i18n = new I18n(pageName);
+
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