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