LEFT | RIGHT |
(no file at all) | |
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 # | 108 # |
109 # Localizable files helpers | 109 # Localizable files helpers |
110 # | 110 # |
111 | 111 |
112 @staticmethod | 112 @staticmethod |
113 def localizable_file_filename(locale, filename): | 113 def localizable_file_filename(locale, filename): |
114 return 'locales/%s/%s' % (locale, filename) | 114 return 'locales/%s/%s' % (locale, filename) |
115 | 115 |
116 def list_localizable_files(self): | 116 def list_localizable_files(self): |
117 default_locale = self.read_config().get('general', 'defaultlocale') | 117 default_locale = self.read_config().get('general', 'defaultlocale') |
118 return filter( | 118 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', |
119 lambda f: os.path.splitext(f)[1].lower() != '.json', | 119 self.list_files('locales/%s' % default_locale)) |
120 self.list_files('locales/%s' % default_locale) | |
121 ) | |
122 | 120 |
123 def has_localizable_file(self, locale, filename): | 121 def has_localizable_file(self, locale, filename): |
124 return self.has_file(self.localizable_file_filename(locale, filename)) | 122 return self.has_file(self.localizable_file_filename(locale, filename)) |
125 | 123 |
126 def read_localizable_file(self, locale, filename): | 124 def read_localizable_file(self, locale, filename): |
127 return self.read_file(self.localizable_file_filename(locale, filename),
binary=True)[0] | 125 return self.read_file(self.localizable_file_filename(locale, filename),
binary=True)[0] |
128 | 126 |
129 # | 127 # |
130 # Static file helpers | 128 # Static file helpers |
131 # | 129 # |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if self.has_locale(locale, page): | 173 if self.has_locale(locale, page): |
176 filename = self.locale_filename(locale, page) | 174 filename = self.locale_filename(locale, page) |
177 filedata, filepath = self.read_file(filename) | 175 filedata, filepath = self.read_file(filename) |
178 try: | 176 try: |
179 localedata = json.loads(filedata) | 177 localedata = json.loads(filedata) |
180 for key, value in localedata.iteritems(): | 178 for key, value in localedata.iteritems(): |
181 result[key] = value['message'] | 179 result[key] = value['message'] |
182 except KeyError as ke: | 180 except KeyError as ke: |
183 if ke.message != 'message': | 181 if ke.message != 'message': |
184 raise | 182 raise |
185 raise ValueError( | 183 raise ValueError('The content of translations file for page ' |
186 'The content of translations file for page "{}", ' | 184 '"{}", language "{}" ({}) is not a valid ' |
187 'language "{}" ({}) is not a valid translations file: ' | 185 'translations file: "message" key is missing ' |
188 '"message" key is missing for string: "{}"' | 186 'for string: "{}"'.format(page, locale, |
189 .format(page, locale, filepath, key) | 187 filepath, key)) |
190 ) | |
191 except (AttributeError, ValueError): | 188 except (AttributeError, ValueError): |
192 raise ValueError( | 189 raise ValueError('The content of translations file for page ' |
193 'The content of translations file for page "{}", ' | 190 '"{}", language "{}" ({}) is not a valid ' |
194 'language "{}" ({}) is not a valid JSON dictionary' | 191 'JSON object'.format(page, locale, filepath)) |
195 .format(page, locale, filepath) | |
196 ) | |
197 | 192 |
198 return result | 193 return result |
199 | 194 |
200 # | 195 # |
201 # Template helpers | 196 # Template helpers |
202 # | 197 # |
203 | 198 |
204 @staticmethod | 199 @staticmethod |
205 def template_filename(template): | 200 def template_filename(template): |
206 return 'templates/%s.tmpl' % template | 201 return 'templates/%s.tmpl' % template |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 'resolve_link', | 445 'resolve_link', |
451 'read_config', | 446 'read_config', |
452 'read_template', | 447 'read_template', |
453 'read_locale', | 448 'read_locale', |
454 'read_include', | 449 'read_include', |
455 'exec_file', | 450 'exec_file', |
456 ]: | 451 ]: |
457 setattr(source, fname, _memoize(getattr(source, fname))) | 452 setattr(source, fname, _memoize(getattr(source, fname))) |
458 | 453 |
459 return source | 454 return source |
LEFT | RIGHT |