Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: cms/bin/translate.py

Issue 29329499: Issue 3246 - Strip empty locale files provided by Crowdin (Closed)
Left Patch Set: Parse the JSON instead of using regexp Created Oct. 30, 2015, 12:02 p.m.
Right Patch Set: Don't catch ValueError if JSON files won't parse Created Oct. 30, 2015, 6:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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,
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 try: 266 locale_file_contents = json.load(source_file)
267 locale_file_contents = json.load(source_file)
268 except ValueError:
269 continue
Wladimir Palant 2015/10/30 18:02:40 I don't think that sweeping exceptions under the c
kzar 2015/10/30 18:17:29 Fair point, this might hide an unrelated issue. (I
270 if len(locale_file_contents): 267 if len(locale_file_contents):
271 with codecs.open(output_path, "wb", "utf-8") as target_file: 268 with codecs.open(output_path, "wb", "utf-8") as target_file:
272 json.dump(locale_file_contents, target_file, ensure_ascii=False, 269 json.dump(locale_file_contents, target_file, ensure_ascii=False,
273 sort_keys=True, indent=2, separators=(",", ": ")) 270 sort_keys=True, indent=2, separators=(",", ": "))
274 271
275 def crowdin_sync(source_dir, crowdin_api_key): 272 def crowdin_sync(source_dir, crowdin_api_key):
276 with FileSource(source_dir) as source: 273 with FileSource(source_dir) as source:
277 config = source.read_config() 274 config = source.read_config()
278 defaultlocale = config.get("general", "defaultlocale") 275 defaultlocale = config.get("general", "defaultlocale")
279 crowdin_project_name = config.get("general", "crowdin-project-name") 276 crowdin_project_name = config.get("general", "crowdin-project-name")
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if __name__ == "__main__": 316 if __name__ == "__main__":
320 if len(sys.argv) < 3: 317 if len(sys.argv) < 3:
321 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]"
322 sys.exit(1) 319 sys.exit(1)
323 320
324 logging.basicConfig() 321 logging.basicConfig()
325 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)
326 323
327 source_dir, crowdin_api_key = sys.argv[1:3] 324 source_dir, crowdin_api_key = sys.argv[1:3]
328 crowdin_sync(source_dir, crowdin_api_key) 325 crowdin_sync(source_dir, crowdin_api_key)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld