Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 filename = self.locale_filename(locale, page) | 177 filename = self.locale_filename(locale, page) |
178 filedata, filepath = self.read_file(filename) | 178 filedata, filepath = self.read_file(filename) |
179 try: | 179 try: |
180 localedata = json.loads(filedata) | 180 localedata = json.loads(filedata) |
181 for key, value in localedata.iteritems(): | 181 for key, value in localedata.iteritems(): |
182 result[key] = value['message'] | 182 result[key] = value['message'] |
183 except KeyError as ke: | |
184 if ke.message != 'message': | |
185 raise | |
186 raise ValueError( | |
187 'The content of translations file for page "{}", ' | |
188 'language "{}" ({}) is not a valid translations file: ' | |
189 '"message" key is missing for string: "{}"' | |
190 .format(page, locale, filepath, key) | |
191 ) | |
183 except (AttributeError, ValueError): | 192 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( | 193 raise ValueError( |
185 'The content of translations file for page "{}", ' | 194 'The content of translations file for page "{}", ' |
186 'language "{}" ({}) is not a valid JSON dictionary' | 195 'language "{}" ({}) is not a valid JSON dictionary' |
187 .format(page, locale, filepath) | 196 .format(page, locale, filepath) |
188 ) | 197 ) |
189 | 198 |
190 return result | 199 return result |
191 | 200 |
192 # | 201 # |
193 # Template helpers | 202 # Template helpers |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 'resolve_link', | 451 'resolve_link', |
443 'read_config', | 452 'read_config', |
444 'read_template', | 453 'read_template', |
445 'read_locale', | 454 'read_locale', |
446 'read_include', | 455 'read_include', |
447 'exec_file', | 456 'exec_file', |
448 ]: | 457 ]: |
449 setattr(source, fname, _memoize(getattr(source, fname))) | 458 setattr(source, fname, _memoize(getattr(source, fname))) |
450 | 459 |
451 return source | 460 return source |
LEFT | RIGHT |