| Index: cms/sources.py |
| =================================================================== |
| --- a/cms/sources.py |
| +++ b/cms/sources.py |
| @@ -169,20 +169,28 @@ |
| def read_locale(self, locale, page): |
| default_locale = self.read_config().get('general', 'defaultlocale') |
| result = collections.OrderedDict() |
| if locale != default_locale: |
| result.update(self.read_locale(default_locale, page)) |
| if self.has_locale(locale, page): |
| - filedata = self.read_file(self.locale_filename(locale, page))[0] |
| - localedata = json.loads(filedata) |
| - for key, value in localedata.iteritems(): |
| - result[key] = value['message'] |
| + filename = self.locale_filename(locale, page) |
| + filedata, filepath = self.read_file(filename) |
| + try: |
| + localedata = json.loads(filedata) |
| + for key, value in localedata.iteritems(): |
| + result[key] = value['message'] |
| + 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
|
| + raise ValueError( |
| + 'The content of translations file for page "{}", ' |
| + 'language "{}" ({}) is not a valid JSON dictionary' |
| + .format(page, locale, filepath) |
| + ) |
| return result |
| # |
| # Template helpers |
| # |
| @staticmethod |