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: Created Oct. 29, 2015, 6:35 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..b0ae5ddf3e83eba67843edcdcf53f501cd41d7d0 100644
--- a/cms/bin/translate.py
+++ b/cms/bin/translate.py
@@ -22,7 +22,7 @@ import json
import logging
import os
import posixpath
-import shutil
+import re
import sys
import urllib
import zipfile
@@ -252,6 +252,7 @@ def download_translations(crowdin_api, source_dir, required_locales):
if f.lower().endswith(".json"):
os.remove(os.path.join(root, f))
# Then extract the new ones in place
+ non_empty_file_regexp = re.compile(r"[^\s{}[\]]")
for member in archive.namelist():
path, file_name = posixpath.split(member)
ext = posixpath.splitext(file_name)[1]
@@ -262,9 +263,11 @@ 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:
+ locale_file_contents = source_file.read()
+ if re.search(non_empty_file_regexp, locale_file_contents):
Wladimir Palant 2015/10/29 19:12:35 I don't think that using regular expressions on JS
kzar 2015/10/30 12:03:03 Done.
+ with open(output_path, "wb") as target_file:
+ target_file.write(locale_file_contents)
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