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

Unified Diff: cms/bin/translate.py

Issue 29329499: Issue 3246 - Strip empty locale files provided by Crowdin (Closed)
Patch Set: Parse the JSON instead of using regexp Created Oct. 30, 2015, 12:02 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/bin/translate.py
diff --git a/cms/bin/translate.py b/cms/bin/translate.py
index 5a855be517d056a698b5018f769ac6883708e011..7d432ff908339ff930c1ea54061e9a3be750ef46 100644
--- a/cms/bin/translate.py
+++ b/cms/bin/translate.py
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+import codecs
import collections
import io
import itertools
@@ -22,7 +23,6 @@ import json
import logging
import os
import posixpath
-import shutil
import sys
import urllib
import zipfile
@@ -262,9 +262,15 @@ def download_translations(crowdin_api, source_dir, required_locales):
locale_path, inverted_required_locales[locale],
*file_path + [file_name]
)
- with archive.open(member) as source_file, \
- open(output_path, "wb") as target_file:
- shutil.copyfileobj(source_file, target_file)
+ with archive.open(member) as source_file:
+ try:
+ locale_file_contents = json.load(source_file)
+ except ValueError:
+ 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
+ if len(locale_file_contents):
+ with codecs.open(output_path, "wb", "utf-8") as target_file:
+ json.dump(locale_file_contents, target_file, ensure_ascii=False,
+ sort_keys=True, indent=2, separators=(",", ": "))
def crowdin_sync(source_dir, crowdin_api_key):
with FileSource(source_dir) as source:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld