| Left: | ||
| Right: |
| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 def has_static(self, filename): | 140 def has_static(self, filename): |
| 141 return self.has_file(self.static_filename(filename)) | 141 return self.has_file(self.static_filename(filename)) |
| 142 | 142 |
| 143 def read_static(self, filename): | 143 def read_static(self, filename): |
| 144 return self.read_file(self.static_filename(filename), binary=True)[0] | 144 return self.read_file(self.static_filename(filename), binary=True)[0] |
| 145 | 145 |
| 146 # | 146 # |
| 147 # Locale helpers | 147 # Locale helpers |
| 148 # | 148 # |
| 149 | 149 |
| 150 @classmethod | 150 def locale_filename(self, locale, page): |
| 151 def locale_filename(cls, locale, page): | 151 config = self.read_config() |
|
Vasily Kuznetsov
2018/01/12 19:56:49
Unfortunately I had to also make this substantive
Jon Sonesen
2018/01/19 04:45:37
Hm, I have played with it a fair amount and it see
Vasily Kuznetsov
2018/01/19 15:34:29
Checked on help.eyeo.com, web.acceptableads.org, w
| |
| 152 return cls.localizable_file_filename(locale, page + '.json') | 152 try: |
| 153 page = config.get('locale_overrides', page) | |
| 154 except ConfigParser.Error: | |
| 155 pass | |
| 156 return self.localizable_file_filename(locale, page + '.json') | |
| 153 | 157 |
| 154 def list_locales(self): | 158 def list_locales(self): |
| 155 result = set() | 159 result = set() |
| 156 for filename in self.list_files('locales'): | 160 for filename in self.list_files('locales'): |
| 157 if '/' in filename: | 161 if '/' in filename: |
| 158 locale, path = filename.split('/', 1) | 162 locale, path = filename.split('/', 1) |
| 159 result.add(locale) | 163 result.add(locale) |
| 160 return result | 164 return result |
| 161 | 165 |
| 162 def has_locale(self, locale, page): | 166 def has_locale(self, locale, page): |
| 163 config = self.read_config() | |
| 164 try: | |
| 165 page = config.get('locale_overrides', page) | |
| 166 except ConfigParser.Error: | |
| 167 pass | |
| 168 return self.has_file(self.locale_filename(locale, page)) | 167 return self.has_file(self.locale_filename(locale, page)) |
| 169 | 168 |
| 170 def read_locale(self, locale, page): | 169 def read_locale(self, locale, page): |
| 171 default_locale = self.read_config().get('general', 'defaultlocale') | 170 default_locale = self.read_config().get('general', 'defaultlocale') |
| 172 result = collections.OrderedDict() | 171 result = collections.OrderedDict() |
| 173 if locale != default_locale: | 172 if locale != default_locale: |
| 174 result.update(self.read_locale(default_locale, page)) | 173 result.update(self.read_locale(default_locale, page)) |
| 175 | 174 |
| 176 if self.has_locale(locale, page): | 175 if self.has_locale(locale, page): |
| 177 filename = self.locale_filename(locale, page) | 176 filename = self.locale_filename(locale, page) |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 'resolve_link', | 450 'resolve_link', |
| 452 'read_config', | 451 'read_config', |
| 453 'read_template', | 452 'read_template', |
| 454 'read_locale', | 453 'read_locale', |
| 455 'read_include', | 454 'read_include', |
| 456 'exec_file', | 455 'exec_file', |
| 457 ]: | 456 ]: |
| 458 setattr(source, fname, _memoize(getattr(source, fname))) | 457 setattr(source, fname, _memoize(getattr(source, fname))) |
| 459 | 458 |
| 460 return source | 459 return source |
| OLD | NEW |