| 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 collections | 19 import collections |
| 19 import io | 20 import io |
| 20 import itertools | 21 import itertools |
| 21 import json | 22 import json |
| 22 import logging | 23 import logging |
| 23 import os | 24 import os |
| 24 import posixpath | 25 import posixpath |
| 25 import shutil | |
| 26 import sys | 26 import sys |
| 27 import urllib | 27 import urllib |
| 28 import zipfile | 28 import zipfile |
| 29 | 29 |
| 30 import urllib3 | 30 import urllib3 |
| 31 | 31 |
| 32 import cms.utils | 32 import cms.utils |
| 33 from cms.sources import FileSource | 33 from cms.sources import FileSource |
| 34 | 34 |
| 35 logger = logging.getLogger("cms.bin.translate") | 35 logger = logging.getLogger("cms.bin.translate") |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 for member in archive.namelist(): | 255 for member in archive.namelist(): |
| 256 path, file_name = posixpath.split(member) | 256 path, file_name = posixpath.split(member) |
| 257 ext = posixpath.splitext(file_name)[1] | 257 ext = posixpath.splitext(file_name)[1] |
| 258 path_parts = path.split(posixpath.sep) | 258 path_parts = path.split(posixpath.sep) |
| 259 locale, file_path = path_parts[0], path_parts[1:] | 259 locale, file_path = path_parts[0], path_parts[1:] |
| 260 if ext.lower() == ".json" and locale in inverted_required_locales: | 260 if ext.lower() == ".json" and locale in inverted_required_locales: |
| 261 output_path = os.path.join( | 261 output_path = os.path.join( |
| 262 locale_path, inverted_required_locales[locale], | 262 locale_path, inverted_required_locales[locale], |
| 263 *file_path + [file_name] | 263 *file_path + [file_name] |
| 264 ) | 264 ) |
| 265 with archive.open(member) as source_file, \ | 265 with archive.open(member) as source_file: |
| 266 open(output_path, "wb") as target_file: | 266 locale_file_contents = json.load(source_file) |
| 267 shutil.copyfileobj(source_file, target_file) | 267 if len(locale_file_contents): |
| 268 with codecs.open(output_path, "wb", "utf-8") as target_file: |
| 269 json.dump(locale_file_contents, target_file, ensure_ascii=False, |
| 270 sort_keys=True, indent=2, separators=(",", ": ")) |
| 268 | 271 |
| 269 def crowdin_sync(source_dir, crowdin_api_key): | 272 def crowdin_sync(source_dir, crowdin_api_key): |
| 270 with FileSource(source_dir) as source: | 273 with FileSource(source_dir) as source: |
| 271 config = source.read_config() | 274 config = source.read_config() |
| 272 defaultlocale = config.get("general", "defaultlocale") | 275 defaultlocale = config.get("general", "defaultlocale") |
| 273 crowdin_project_name = config.get("general", "crowdin-project-name") | 276 crowdin_project_name = config.get("general", "crowdin-project-name") |
| 274 | 277 |
| 275 crowdin_api = CrowdinAPI(crowdin_api_key, crowdin_project_name) | 278 crowdin_api = CrowdinAPI(crowdin_api_key, crowdin_project_name) |
| 276 | 279 |
| 277 logger.info("Requesting project information...") | 280 logger.info("Requesting project information...") |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if __name__ == "__main__": | 316 if __name__ == "__main__": |
| 314 if len(sys.argv) < 3: | 317 if len(sys.argv) < 3: |
| 315 print >>sys.stderr, "Usage: python -m cms.bin.translate www_directory crowdi
n_project_api_key [logging_level]" | 318 print >>sys.stderr, "Usage: python -m cms.bin.translate www_directory crowdi
n_project_api_key [logging_level]" |
| 316 sys.exit(1) | 319 sys.exit(1) |
| 317 | 320 |
| 318 logging.basicConfig() | 321 logging.basicConfig() |
| 319 logger.setLevel(sys.argv[3] if len(sys.argv) > 3 else logging.INFO) | 322 logger.setLevel(sys.argv[3] if len(sys.argv) > 3 else logging.INFO) |
| 320 | 323 |
| 321 source_dir, crowdin_api_key = sys.argv[1:3] | 324 source_dir, crowdin_api_key = sys.argv[1:3] |
| 322 crowdin_sync(source_dir, crowdin_api_key) | 325 crowdin_sync(source_dir, crowdin_api_key) |
| OLD | NEW |