| 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() |