| Index: translations.py |
| =================================================================== |
| --- a/translations.py |
| +++ b/translations.py |
| @@ -1,16 +1,17 @@ |
| #!/usr/bin/env python |
| import filecmp |
| import os |
| import re |
| import shutil |
| import sys |
| import urllib2 |
| +from lxml import etree |
| from StringIO import StringIO |
| from zipfile import ZipFile |
| import buildtools.localeTools |
| BASE_PATH = os.path.dirname(os.path.abspath(__file__)) |
| LOCALES_PATH = os.path.join(BASE_PATH, "mobile", "android", "base", "locales", |
| "adblockbrowser") |
| @@ -29,17 +30,23 @@ def get_translations(api_key): |
| result = urllib2.urlopen("%s/export?key=%s" % (PROJECT_URL, api_key)) |
| if result.read().find("<success") < 0: |
| raise Exception("Export failed: " + result) |
| result = urllib2.urlopen("%s/download/all.zip?key=%s" % |
| (PROJECT_URL, api_key)) |
| zip = ZipFile(StringIO(result.read())) |
| + progress_for_translation = get_progress_for_translation_dictionary(api_key) |
| for info in zip.infolist(): |
| + # skip languages without translations |
| + index = info.filename.index('/') |
| + if progress_for_translation[info.filename[:index]] == '0': |
| + continue |
| + |
| if not info.filename.endswith(".dtd"): |
| continue |
| dir, file = os.path.split(info.filename) |
| if not re.match(r"^[\w\-]+$", dir) or dir == DEFAULT_LOCALE: |
| continue |
| mapping = buildtools.localeTools.langMappingGecko |
| @@ -52,16 +59,26 @@ def get_translations(api_key): |
| continue |
| path = os.path.join(LOCALES_PATH, dir, file) |
| if not os.path.exists(os.path.dirname(path)): |
| os.makedirs(os.path.dirname(path)) |
| with open(path, "w") as file: |
| file.write(data) |
| +def get_progress_for_translation_dictionary(api_key): |
| + parser = etree.HTMLParser() |
| + f = urllib2.urlopen('{}/status?key={}'.format(PROJECT_URL, api_key)) |
| + tree = etree.parse(f, parser) |
| + languages = {} |
| + for language in tree.iter(): |
| + languages.update({ |
| + language.findtext('code'): language.findtext('translated_progress') |
| + }) |
| + return languages |
| def remove_redundant_translations(): |
| 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: |