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

Unified Diff: translations.py

Issue 29325540: Issue 2977 - Don't add redundant translations (Closed)
Patch Set: Created Sept. 2, 2015, 12:25 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: translations.py
===================================================================
--- a/translations.py
+++ b/translations.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python
+import filecmp
import os
import re
+import shutil
import sys
import urllib2
from StringIO import StringIO
@@ -13,6 +15,7 @@
LOCALES_PATH = os.path.join(BASE_PATH, "mobile", "android", "base", "locales",
"adblockbrowser")
PROJECT_URL = "http://api.crowdin.net/api/project/adblockbrowserandroid"
+DEFAULT_LOCALE = "en-US"
def print_usage():
print >>sys.stderr, "Usage: %s get API_KEY" % os.path.basename(sys.argv[0])
@@ -34,7 +37,7 @@
continue
dir, file = os.path.split(info.filename)
- if not re.match(r"^[\w\-]+$", dir) or dir == "en-US":
+ if not re.match(r"^[\w\-]+$", dir) or dir == DEFAULT_LOCALE:
continue
mapping = buildtools.localeTools.langMappingGecko
@@ -52,6 +55,15 @@
with open(path, "w") as file:
file.write(data)
+def remove_redundant_translations():
Felix Dahlke 2015/09/02 12:29:16 It feels a bit unelegant to do this as a separate
+ default_locale_path = os.path.join(LOCALES_PATH, DEFAULT_LOCALE)
+ for locale in os.listdir(LOCALES_PATH):
+ if locale == DEFAULT_LOCALE:
+ continue
+ locale_path = os.path.join(LOCALES_PATH, locale)
+ if not filecmp.dircmp(locale_path, default_locale_path).diff_files:
+ shutil.rmtree(locale_path)
+
if __name__ == "__main__":
if len(sys.argv) < 3:
print_usage()
@@ -63,3 +75,4 @@
sys.exit(2)
get_translations(api_key)
+ remove_redundant_translations()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld