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

Side by Side Diff: cms/sources.py

Issue 29600635: Noissue - Improve error reporting for broken locale files (Closed)
Patch Set: Created Nov. 7, 2017, 6:53 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
« no previous file with comments | « no previous file | 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 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 pass 167 pass
168 return self.has_file(self.locale_filename(locale, page)) 168 return self.has_file(self.locale_filename(locale, page))
169 169
170 def read_locale(self, locale, page): 170 def read_locale(self, locale, page):
171 default_locale = self.read_config().get('general', 'defaultlocale') 171 default_locale = self.read_config().get('general', 'defaultlocale')
172 result = collections.OrderedDict() 172 result = collections.OrderedDict()
173 if locale != default_locale: 173 if locale != default_locale:
174 result.update(self.read_locale(default_locale, page)) 174 result.update(self.read_locale(default_locale, page))
175 175
176 if self.has_locale(locale, page): 176 if self.has_locale(locale, page):
177 filedata = self.read_file(self.locale_filename(locale, page))[0] 177 filename = self.locale_filename(locale, page)
178 localedata = json.loads(filedata) 178 filedata, filepath = self.read_file(filename)
179 for key, value in localedata.iteritems(): 179 try:
180 result[key] = value['message'] 180 localedata = json.loads(filedata)
181 for key, value in localedata.iteritems():
182 result[key] = value['message']
183 except (AttributeError, ValueError):
Vasily Kuznetsov 2017/11/07 18:57:35 ValueError if JSON parsing fails, AttributeError i
mathias 2017/11/07 20:13:30 What about the KeyError when 'message' is not in t
Vasily Kuznetsov 2017/11/27 18:35:23 That's a bit of a different error, but sure, let's
184 raise ValueError(
185 'The content of translations file for page "{}", '
186 'language "{}" ({}) is not a valid JSON dictionary'
187 .format(page, locale, filepath)
188 )
181 189
182 return result 190 return result
183 191
184 # 192 #
185 # Template helpers 193 # Template helpers
186 # 194 #
187 195
188 @staticmethod 196 @staticmethod
189 def template_filename(template): 197 def template_filename(template):
190 return 'templates/%s.tmpl' % template 198 return 'templates/%s.tmpl' % template
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 'resolve_link', 442 'resolve_link',
435 'read_config', 443 'read_config',
436 'read_template', 444 'read_template',
437 'read_locale', 445 'read_locale',
438 'read_include', 446 'read_include',
439 'exec_file', 447 'exec_file',
440 ]: 448 ]:
441 setattr(source, fname, _memoize(getattr(source, fname))) 449 setattr(source, fname, _memoize(getattr(source, fname)))
442 450
443 return source 451 return source
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld