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

Delta Between Two Patch Sets: background.js

Issue 8560083: adblockplusopera: Port UI code from Chrome (Closed)
Left Patch Set: Created Oct. 16, 2012, 2:16 p.m.
Right Patch Set: Created Oct. 19, 2012, 4: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 | « no previous file | button.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 var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscr iption; 1 var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscr iption;
2 var WhitelistFilter = require("filterClasses").WhitelistFilter; 2 var WhitelistFilter = require("filterClasses").WhitelistFilter;
3 var FilterNotifier = require("filterNotifier").FilterNotifier; 3 var FilterNotifier = require("filterNotifier").FilterNotifier;
4 var FilterStorage = require("filterStorage").FilterStorage; 4 var FilterStorage = require("filterStorage").FilterStorage;
5 var Prefs = require("prefs").Prefs; 5 var Prefs = require("prefs").Prefs;
6 var Synchronizer = require("synchronizer").Synchronizer; 6 var Synchronizer = require("synchronizer").Synchronizer;
7 var Subscription = require("subscriptionClasses").Subscription; 7 var Subscription = require("subscriptionClasses").Subscription;
8 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; 8 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
9 var Utils = require("utils").Utils; 9 var Utils = require("utils").Utils;
10 10
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 toolbar.addItem(toolbarButton); 181 toolbar.addItem(toolbarButton);
182 else 182 else
183 toolbar.removeItem(toolbarButton); 183 toolbar.removeItem(toolbarButton);
184 } 184 }
185 185
186 function getJson(url) 186 function getJson(url)
187 { 187 {
188 var request = new XMLHttpRequest(); 188 var request = new XMLHttpRequest();
189 request.open("GET", url, false); 189 request.open("GET", url, false);
190 request.responseType = "json"; 190 request.responseType = "json";
191 request.send(); 191 request.send();
Wladimir Palant 2012/10/17 10:17:14 What happens if the file doesn't exist? Won't this
Felix Dahlke 2012/10/18 08:08:46 Yes, you're right. Done.
192 return request.response; 192 return request.response;
193 } 193 }
194 194
195 function loadMessagesForLocale(locale) 195 function loadMessagesForLocale(locale)
196 { 196 {
197 var messagesFileName = "messages.json"; 197 var messagesFileName = "messages.json";
198 var messagesPath; 198 var messagesPath;
199 if (locale) 199 if (locale)
200 messagesPath = "locales/" + locale + "/" + messagesFileName; 200 messagesPath = "locales/" + locale + "/" + messagesFileName;
201 else 201 else
202 messagesPath = messagesFileName; 202 messagesPath = messagesFileName;
203 203
204 var messages = getJson(messagesPath); 204 var messages = getJson(messagesPath);
205 if (!messages)
206 {
207 console.error("Failed to load messages for locale "
208 + (locale ? locale : "default"));
209 return;
210 }
211
205 for (var i in messages) 212 for (var i in messages)
206 i18nMessages[i] = messages[i]; 213 i18nMessages[i] = messages[i];
207 } 214 }
208 215
209 function loadI18nMessages() 216 function loadI18nMessages()
Wladimir Palant 2012/10/17 10:17:14 From the look of it, this function will never load
Felix Dahlke 2012/10/18 08:08:46 It does, that's the locale I use.
210 { 217 {
218 // Could be parsed from config.xml
219 var defaultLocale = "en";
220
211 i18nMessages = {}; 221 i18nMessages = {};
212 222 loadMessagesForLocale(defaultLocale);
213 var baseLocale = "en";
Wladimir Palant 2012/10/17 10:17:14 Is there an easy way to get the default locale fro
Felix Dahlke 2012/10/18 08:08:46 Oh, didn't notice it was specified there. I have j
214 var language = locale.split("-")[0];
Wladimir Palant 2012/10/17 10:17:14 locale is undefined?
Felix Dahlke 2012/10/18 08:08:46 No, it's a global. It's defined in a locale-specif
215
216 if (baseLocale !== language)
217 loadMessagesForLocale(baseLocale);
218
219 if (locale !== language)
Wladimir Palant 2012/10/17 10:17:14 What's the point of this check? Shouldn't we alway
Felix Dahlke 2012/10/18 08:08:46 "language" is just the language part, without the
220 loadMessagesForLocale(language);
221
222 loadMessagesForLocale(); 223 loadMessagesForLocale();
Wladimir Palant 2012/10/17 10:17:14 Locale-independent messages.json? Sounds pointless
Felix Dahlke 2012/10/18 08:08:46 messages.json exists once for each locale and is l
223 } 224 }
224 225
225 setDefaultOptions(); 226 setDefaultOptions();
226 createToolbarButton(); 227 createToolbarButton();
227 refreshToolbarButton(); 228 refreshToolbarButton();
228 loadI18nMessages(); 229 loadI18nMessages();
LEFTRIGHT
« no previous file | button.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld