Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 function localize(translations, locale) | 45 function localize(translations, locale) |
46 { | 46 { |
47 if (locale in translations) | 47 if (locale in translations) |
48 return translations[locale]; | 48 return translations[locale]; |
49 | 49 |
50 let languagePart = locale.substring(0, locale.indexOf("-")); | 50 let languagePart = locale.substring(0, locale.indexOf("-")); |
51 if (languagePart && languagePart in translations) | 51 if (languagePart && languagePart in translations) |
52 return translations[languagePart]; | 52 return translations[languagePart]; |
53 | 53 |
54 let defaultLocale = "en"; | 54 let defaultLocale = "en-US"; |
Wladimir Palant
2013/07/19 15:17:52
Actually, our default locale is always en-US - and
Felix Dahlke
2013/07/19 17:07:01
Done.
| |
55 return translations[defaultLocale]; | 55 return translations[defaultLocale]; |
56 } | 56 } |
57 | 57 |
58 /** | 58 /** |
59 * The object providing actual downloading functionality. | 59 * The object providing actual downloading functionality. |
60 * @type Downloader | 60 * @type Downloader |
61 */ | 61 */ |
62 let downloader = null; | 62 let downloader = null; |
63 | 63 |
64 /** | 64 /** |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 Prefs.notificationdata.shown = []; | 155 Prefs.notificationdata.shown = []; |
156 saveNotificationData(); | 156 saveNotificationData(); |
157 } | 157 } |
158 | 158 |
159 let {application, addonVersion} = require("info"); | 159 let {application, addonVersion} = require("info"); |
160 let notifications = Prefs.notificationdata.data.notifications; | 160 let notifications = Prefs.notificationdata.data.notifications; |
161 let notificationToShow = null; | 161 let notificationToShow = null; |
162 for each (let notification in notifications) | 162 for each (let notification in notifications) |
163 { | 163 { |
164 if ((typeof notification.severity == "undefined" || notification.severity === "information") | 164 if ((typeof notification.severity == "undefined" || notification.severity === "information") |
165 && Prefs.notificationdata.shown.indexOf(notification.timestamp) !== -1 ) | 165 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) |
166 continue; | 166 continue; |
167 | 167 |
168 if (notification.platforms instanceof Array | 168 if (notification.platforms instanceof Array |
169 && notification.platforms.indexOf(application) === -1) | 169 && notification.platforms.indexOf(application) === -1) |
170 continue; | 170 continue; |
171 | 171 |
172 if ("minVersion" in notification | 172 if ("minVersion" in notification |
173 && Services.vc.compare(addonVersion, notification.minVersion) < 0) | 173 && Services.vc.compare(addonVersion, notification.minVersion) < 0) |
174 continue; | 174 continue; |
175 | 175 |
176 if ("maxVersion" in notification | 176 if ("maxVersion" in notification |
177 && Services.vc.compare(addonVersion, notification.maxVersion) > 0) | 177 && Services.vc.compare(addonVersion, notification.maxVersion) > 0) |
178 continue; | 178 continue; |
179 | 179 |
180 if (!notificationToShow | 180 if (!notificationToShow |
181 || getNumericalSeverity(notification) > getNumericalSeverity(notificat ionToShow)) | 181 || getNumericalSeverity(notification) > getNumericalSeverity(notificat ionToShow)) |
182 notificationToShow = notification; | 182 notificationToShow = notification; |
183 } | 183 } |
184 | 184 |
185 if (notificationToShow && "timestamp" in notificationToShow) | 185 if (notificationToShow && "id" in notificationToShow) |
186 { | 186 { |
187 Prefs.notificationdata.shown.push(notificationToShow.timestamp); | 187 Prefs.notificationdata.shown.push(notificationToShow.id); |
188 saveNotificationData(); | 188 saveNotificationData(); |
189 } | 189 } |
190 | 190 |
191 return notificationToShow; | 191 return notificationToShow; |
192 }, | 192 }, |
193 | 193 |
194 /** | 194 /** |
195 * Localizes the texts of the supplied notification. | 195 * Localizes the texts of the supplied notification. |
196 * @param {Object} notification notification to translate | 196 * @param {Object} notification notification to translate |
197 * @param {String} locale the target locale (optional, defaults to the | 197 * @param {String} locale the target locale (optional, defaults to the |
198 * application locale) | 198 * application locale) |
199 * @return {Object} the translated texts | 199 * @return {Object} the translated texts |
200 */ | 200 */ |
201 getLocalizedTexts: function(notification, locale) | 201 getLocalizedTexts: function(notification, locale) |
202 { | 202 { |
203 locale = locale || Utils.appLocale; | 203 locale = locale || Utils.appLocale; |
204 let textKeys = ["title", "message"]; | 204 let textKeys = ["title", "message"]; |
205 let localizedTexts = []; | 205 let localizedTexts = []; |
206 for each (let key in textKeys) | 206 for each (let key in textKeys) |
207 { | 207 { |
208 if (key in notification) | 208 if (key in notification) |
209 localizedTexts[key] = localize(notification[key], locale); | 209 localizedTexts[key] = localize(notification[key], locale); |
210 } | 210 } |
211 return localizedTexts; | 211 return localizedTexts; |
212 } | 212 } |
213 }; | 213 }; |
214 Notification.init(); | 214 Notification.init(); |
LEFT | RIGHT |