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

Delta Between Two Patch Sets: ext/common.js

Issue 29376555: [adblockplus] Issue 4915 - Expose ext.i18n for background pages (Closed)
Left Patch Set: Removed obsolete code addressed review comments Created March 1, 2017, 2:45 p.m.
Right Patch Set: Removed I18n class Created March 2, 2017, 5:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « ext/background.js ('k') | ext/content.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 this._port.on("ext_message", wrapper); 79 this._port.on("ext_message", wrapper);
80 }, 80 },
81 81
82 removeListener: function(listener) 82 removeListener: function(listener)
83 { 83 {
84 if (listener[wrapperSymbol]) 84 if (listener[wrapperSymbol])
85 this._port.off("ext_message", listener[wrapperSymbol]); 85 this._port.off("ext_message", listener[wrapperSymbol]);
86 } 86 }
87 }; 87 };
88 88
89 let I18n = global.ext._I18n = function(pageName) 89 let pageName = "global";
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
90 { 90 if (typeof location !== "undefined")
91 // Randomize URI to work around bug 719376 91 pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, "");
92 this.stringBundle = Services.strings.createBundle(
93 "chrome://adblockplus/locale/" + pageName + ".properties?" + Math.random() );
94 };
95 92
96 I18n.prototype = { 93 let stringBundle = Services.strings.createBundle(
97 getMessage(key) 94 "chrome://adblockplus/locale/" + pageName + ".properties?" + Math.random());
95
96 global.ext.i18n = {
97 getMessage(key, args)
98 { 98 {
99 try { 99 try {
100 return this.stringBundle.GetStringFromName(key); 100 return 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
101 } 101 }
102 catch(e) 102 catch(e)
103 { 103 {
104 // Don't report errors for special strings, these are expected to be 104 // Don't report errors for special strings, these are expected to be
105 // missing. 105 // missing.
106 if (key[0] != "@") 106 if (key[0] != "@")
107 Cu.reportError(e); 107 Cu.reportError(e);
108 return ""; 108 return "";
109 } 109 }
110 } 110 }
111 } 111 };
112
113 let pageName = "global";
114 if (typeof location !== "undefined")
115 pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, "");
116
117 global.ext.i18n = new I18n(pageName);
118 112
119 if (typeof exports == "object") 113 if (typeof exports == "object")
120 exports = global.ext; 114 exports = global.ext;
121 })(this); 115 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld