| Index: ext/common.js |
| diff --git a/ext/common.js b/ext/common.js |
| index c00cfffac710285aeef7b16823cd952067c7ea4c..28fbd651b6877451be77a74aaaab0d658c094a7b 100644 |
| --- a/ext/common.js |
| +++ b/ext/common.js |
| @@ -17,6 +17,10 @@ |
| (function(global) |
| { |
| + const Cu = Components.utils; |
| + |
| + var Services = Cu.import("resource://gre/modules/Services.jsm", {}).Services; |
|
Sebastian Noack
2017/02/20 16:53:20
Please use let in favor of var in new code. (Same
wspee
2017/03/01 14:54:08
Done.
|
| + |
| if (!global.ext) |
| global.ext = {}; |
| @@ -82,6 +86,71 @@ |
| } |
| }; |
| + |
| + global.ext.i18n = (function() |
|
Sebastian Noack
2017/02/20 16:53:20
There is no need for any IIFE in modern code. The
Sebastian Noack
2017/02/20 16:53:20
It seems you forgot to remove ext.i18n from ext/co
wspee
2017/03/01 14:54:08
Done.
wspee
2017/03/01 14:54:08
Done.
|
| + { |
| + if (typeof location == "undefined") |
|
wspee
2017/02/20 13:53:16
This is probably a bad idea, but I'm not sure what
Sebastian Noack
2017/02/20 16:53:20
I might misunderstand, but isn't the "global" bund
wspee
2017/03/01 14:54:08
Yes it is, it does the right thing.
I was thinkin
|
| + var pageName = "global"; |
| + else |
| + var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, ""); |
| + |
| + // Randomize URI to work around bug 719376 |
| + var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/" + pageName + |
| + ".properties?" + Math.random()); |
| + |
| + function getI18nMessage(key) |
| + { |
| + return { |
| + "message": stringBundle.GetStringFromName(key) |
| + }; |
| + } |
| + |
| + function getText(message, args) |
| + { |
| + var text = message.message; |
|
Sebastian Noack
2017/02/20 16:53:20
Perhaps you rather want to use restructuring argum
wspee
2017/03/01 14:54:08
I have removed getText and getI18nMessage altogeth
|
| + var placeholders = message.placeholders; |
| + |
| + if (!args || !placeholders) |
| + return text; |
| + |
| + for (var key in placeholders) |
| + { |
| + var content = placeholders[key].content; |
| + if (!content) |
| + continue; |
| + |
| + var index = parseInt(content.slice(1), 10); |
| + if (isNaN(index)) |
| + continue; |
| + |
| + var replacement = args[index - 1]; |
| + if (typeof replacement === "undefined") |
| + continue; |
| + |
| + text = text.split("$" + key + "$").join(replacement); |
| + } |
| + return text; |
| + } |
| + |
| + return { |
| + getMessage: function(key, args) |
| + { |
| + try{ |
| + var message = getI18nMessage(key); |
| + return getText(message, args); |
| + } |
| + 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); |