OLD | NEW |
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 Loading... |
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 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 ) |
| 192 except (AttributeError, ValueError): |
| 193 raise ValueError( |
| 194 'The content of translations file for page "{}", ' |
| 195 'language "{}" ({}) is not a valid JSON dictionary' |
| 196 .format(page, locale, filepath) |
| 197 ) |
181 | 198 |
182 return result | 199 return result |
183 | 200 |
184 # | 201 # |
185 # Template helpers | 202 # Template helpers |
186 # | 203 # |
187 | 204 |
188 @staticmethod | 205 @staticmethod |
189 def template_filename(template): | 206 def template_filename(template): |
190 return 'templates/%s.tmpl' % template | 207 return 'templates/%s.tmpl' % template |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 'resolve_link', | 451 'resolve_link', |
435 'read_config', | 452 'read_config', |
436 'read_template', | 453 'read_template', |
437 'read_locale', | 454 'read_locale', |
438 'read_include', | 455 'read_include', |
439 'exec_file', | 456 'exec_file', |
440 ]: | 457 ]: |
441 setattr(source, fname, _memoize(getattr(source, fname))) | 458 setattr(source, fname, _memoize(getattr(source, fname))) |
442 | 459 |
443 return source | 460 return source |
OLD | NEW |