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: Don't catch ValueError if JSON files won't parse Created Oct. 30, 2015, 6:13 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..f1cce1de719f1d5c9a60bebd3ca3680ea2086d44 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,12 @@ 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 = json.load(source_file)
+ 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