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

Side by Side Diff: ext/content.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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« ext/common.js ('K') | « ext/common.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 senderID: getOuterWindowID(), 72 senderID: getOuterWindowID(),
73 payload 73 payload
74 }; 74 };
75 if (typeof responseCallback == "function") 75 if (typeof responseCallback == "function")
76 port.emitWithResponse("ext_message", message).then(responseCallback); 76 port.emitWithResponse("ext_message", message).then(responseCallback);
77 else 77 else
78 port.emit("ext_message", message); 78 port.emit("ext_message", message);
79 } 79 }
80 }; 80 };
81 81
82 /* i18n */
83 global.ext.i18n = (function()
84 {
85 var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, "");
86
87 // Randomize URI to work around bug 719376
88 var stringBundle = Services.strings.createBundle("chrome://adblockplus/local e/" + pageName +
89 ".properties?" + Math.random());
90
91 function getI18nMessage(key)
92 {
93 return {
94 "message": stringBundle.GetStringFromName(key)
95 };
96 }
97
98 function getText(message, args)
99 {
100 var text = message.message;
101 var placeholders = message.placeholders;
102
103 if (!args || !placeholders)
104 return text;
105
106 for (var key in placeholders)
107 {
108 var content = placeholders[key].content;
109 if (!content)
110 continue;
111
112 var index = parseInt(content.slice(1), 10);
113 if (isNaN(index))
114 continue;
115
116 var replacement = args[index - 1];
117 if (typeof replacement === "undefined")
118 continue;
119
120 text = text.split("$" + key + "$").join(replacement);
121 }
122 return text;
123 }
124
125 return {
126 getMessage: function(key, args)
127 {
128 try{
129 var message = getI18nMessage(key);
130 return getText(message, args);
131 }
132 catch(e)
133 {
134 // Don't report errors for special strings, these are expected to be
135 // missing.
136 if (key[0] != "@")
137 Cu.reportError(e);
138 return "";
139 }
140 }
141 };
142 })();
143 })(this); 82 })(this);
OLDNEW
« ext/common.js ('K') | « ext/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld