Left: | ||
Right: |
OLD | NEW |
---|---|
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import codecs | 18 import codecs |
19 from collections import OrderedDict | |
19 import ConfigParser | 20 import ConfigParser |
20 import json | 21 import json |
21 import os | 22 import os |
22 from StringIO import StringIO | 23 from StringIO import StringIO |
23 import subprocess | 24 import subprocess |
24 import urlparse | 25 import urlparse |
25 import zipfile | 26 import zipfile |
26 import logging | 27 import logging |
27 | 28 |
28 class Source: | 29 class Source: |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 config = self.read_config() | 163 config = self.read_config() |
163 try: | 164 try: |
164 page = config.get("locale_overrides", page) | 165 page = config.get("locale_overrides", page) |
165 except ConfigParser.Error: | 166 except ConfigParser.Error: |
166 pass | 167 pass |
167 return self.has_file(self.locale_filename(locale, page)) | 168 return self.has_file(self.locale_filename(locale, page)) |
168 | 169 |
169 def read_locale(self, locale, page): | 170 def read_locale(self, locale, page): |
170 default_locale = self.read_config().get("general", "defaultlocale") | 171 default_locale = self.read_config().get("general", "defaultlocale") |
171 if locale == default_locale: | 172 if locale == default_locale: |
172 result = {} | 173 result = OrderedDict() |
kzar
2015/06/15 14:24:28
This is required to keep the correct order of page
Wladimir Palant
2015/06/29 19:05:38
Crowdin isn't very good at keeping that order but
kzar
2015/07/02 12:33:13
I found that it does help in practice for our webs
| |
173 else: | 174 else: |
174 result = dict(self.read_locale(default_locale, page)) | 175 result = OrderedDict(self.read_locale(default_locale, page)) |
175 | 176 |
176 if self.has_locale(locale, page): | 177 if self.has_locale(locale, page): |
177 filedata = self.read_file(self.locale_filename(locale, page)) | 178 filedata = self.read_file(self.locale_filename(locale, page)) |
178 localedata = json.loads(filedata) | 179 localedata = json.loads(filedata) |
179 for key, value in localedata.iteritems(): | 180 for key, value in localedata.iteritems(): |
180 result[key] = value["message"] | 181 result[key] = value["message"] |
181 | 182 |
182 return result | 183 return result |
183 | 184 |
184 # | 185 # |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 path = os.path.join(dir, filename) | 288 path = os.path.join(dir, filename) |
288 if os.path.isfile(path): | 289 if os.path.isfile(path): |
289 result.append(relpath + filename) | 290 result.append(relpath + filename) |
290 elif os.path.isdir(path): | 291 elif os.path.isdir(path): |
291 do_list(path, relpath + filename + "/") | 292 do_list(path, relpath + filename + "/") |
292 do_list(self.get_path(subdir), "") | 293 do_list(self.get_path(subdir), "") |
293 return result | 294 return result |
294 | 295 |
295 def get_cache_dir(self): | 296 def get_cache_dir(self): |
296 return os.path.join(self._dir, "cache") | 297 return os.path.join(self._dir, "cache") |
OLD | NEW |