electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 5db21134aa86019745cd455d13c6c75ef343cd28
parent aa00fa2a5cf3d050a4a8968b3f20e2c20db512d1
Author: ThomasV <thomasv@electrum.org>
Date:   Wed,  3 Jul 2019 16:19:06 +0200

separate push and pull locale

Diffstat:
M.travis.yml | 7++-----
Dcontrib/make_locale | 87-------------------------------------------------------------------------------
Mcontrib/make_tgz | 2+-
Acontrib/pull_locale | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontrib/push_locale | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 127 insertions(+), 93 deletions(-)

diff --git a/.travis.yml b/.travis.yml @@ -23,7 +23,7 @@ cache: script: - tox after_success: - - if [ "$TRAVIS_BRANCH" = "master" ]; then pip install requests && contrib/make_locale; fi + - if [ "$TRAVIS_BRANCH" = "master" ]; then pip install requests && contrib/push_locale; fi - coveralls jobs: include: @@ -44,13 +44,10 @@ jobs: - name: "Android build" language: python python: 3.7 - env: - # reset API key to not have make_locale upload stuff here - - crowdin_api_key= services: - docker install: - - pip install requests && ./contrib/make_locale + - pip install requests && ./contrib/pull_locale - ./contrib/make_packages - sudo docker build --no-cache -t electrum-android-builder-img electrum/gui/kivy/tools script: diff --git a/contrib/make_locale b/contrib/make_locale @@ -1,87 +0,0 @@ -#!/usr/bin/env python3 -import os -import subprocess -import io -import zipfile -import sys - -try: - import requests -except ImportError as e: - sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install <module-name>'") - -os.chdir(os.path.dirname(os.path.realpath(__file__))) -os.chdir('..') - -cmd = "find electrum -type f -name '*.py' -o -name '*.kv'" - -files = subprocess.check_output(cmd, shell=True) - -with open("app.fil", "wb") as f: - f.write(files) - -print("Found {} files to translate".format(len(files.splitlines()))) - -# Generate fresh translation template -if not os.path.exists('electrum/locale'): - os.mkdir('electrum/locale') -cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --output=electrum/locale/messages.pot' -print('Generate template') -os.system(cmd) - -os.chdir('electrum') - -crowdin_identifier = 'electrum' -crowdin_file_name = 'files[electrum-client/messages.pot]' -locale_file_name = 'locale/messages.pot' -crowdin_api_key = None - -filename = os.path.expanduser('~/.crowdin_api_key') -if os.path.exists(filename): - with open(filename) as f: - crowdin_api_key = f.read().strip() - -if "crowdin_api_key" in os.environ: - crowdin_api_key = os.environ["crowdin_api_key"] - -if crowdin_api_key: - # Push to Crowdin - print('Push to Crowdin') - url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key) - with open(locale_file_name, 'rb') as f: - files = {crowdin_file_name: f} - response = requests.request('POST', url, files=files) - print("", "update-file:", "-"*20, response.text, "-"*20, sep="\n") - # Build translations - print('Build translations') - response = requests.request('GET', 'https://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key) - print("", "export:", "-" * 20, response.text, "-" * 20, sep="\n") - -# Download & unzip -print('Download translations') -s = requests.request('GET', 'https://crowdin.com/backend/download/project/' + crowdin_identifier + '.zip').content -zfobj = zipfile.ZipFile(io.BytesIO(s)) - -print('Unzip translations') -for name in zfobj.namelist(): - if not name.startswith('electrum-client/locale'): - continue - if name.endswith('/'): - if not os.path.exists(name[16:]): - os.mkdir(name[16:]) - else: - with open(name[16:], 'wb') as output: - output.write(zfobj.read(name)) - -# Convert .po to .mo -print('Installing') -for lang in os.listdir('locale'): - if lang.startswith('messages'): - continue - # Check LC_MESSAGES folder - mo_dir = 'locale/%s/LC_MESSAGES' % lang - if not os.path.exists(mo_dir): - os.mkdir(mo_dir) - cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang) - print('Installing', lang) - os.system(cmd) diff --git a/contrib/make_tgz b/contrib/make_tgz @@ -8,7 +8,7 @@ PACKAGES="$ROOT_FOLDER"/packages/ LOCALE="$ROOT_FOLDER"/electrum/locale/ if [ ! -d "$LOCALE" ]; then - echo "Run make_locale first!" + echo "Run pull_locale first!" exit 1 fi diff --git a/contrib/pull_locale b/contrib/pull_locale @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +import os +import subprocess +import io +import zipfile +import sys + +try: + import requests +except ImportError as e: + sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install <module-name>'") + +os.chdir(os.path.dirname(os.path.realpath(__file__))) +os.chdir('..') + +cmd = "find electrum -type f -name '*.py' -o -name '*.kv'" + +files = subprocess.check_output(cmd, shell=True) + +with open("app.fil", "wb") as f: + f.write(files) + +print("Found {} files to translate".format(len(files.splitlines()))) + +# Generate fresh translation template +if not os.path.exists('electrum/locale'): + os.mkdir('electrum/locale') +cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --output=electrum/locale/messages.pot' +print('Generate template') +os.system(cmd) + +os.chdir('electrum') + +crowdin_identifier = 'electrum' +crowdin_file_name = 'files[electrum-client/messages.pot]' +locale_file_name = 'locale/messages.pot' + +# Download & unzip +print('Download translations') +s = requests.request('GET', 'https://crowdin.com/backend/download/project/' + crowdin_identifier + '.zip').content +zfobj = zipfile.ZipFile(io.BytesIO(s)) + +print('Unzip translations') +for name in zfobj.namelist(): + if not name.startswith('electrum-client/locale'): + continue + if name.endswith('/'): + if not os.path.exists(name[16:]): + os.mkdir(name[16:]) + else: + with open(name[16:], 'wb') as output: + output.write(zfobj.read(name)) + +# Convert .po to .mo +print('Installing') +for lang in os.listdir('locale'): + if lang.startswith('messages'): + continue + # Check LC_MESSAGES folder + mo_dir = 'locale/%s/LC_MESSAGES' % lang + if not os.path.exists(mo_dir): + os.mkdir(mo_dir) + cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang) + print('Installing', lang) + os.system(cmd) diff --git a/contrib/push_locale b/contrib/push_locale @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +import os +import subprocess +import io +import zipfile +import sys + +try: + import requests +except ImportError as e: + sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install <module-name>'") + +os.chdir(os.path.dirname(os.path.realpath(__file__))) +os.chdir('..') + +cmd = "find electrum -type f -name '*.py' -o -name '*.kv'" + +files = subprocess.check_output(cmd, shell=True) + +with open("app.fil", "wb") as f: + f.write(files) + +print("Found {} files to translate".format(len(files.splitlines()))) + +# Generate fresh translation template +if not os.path.exists('electrum/locale'): + os.mkdir('electrum/locale') +cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --output=electrum/locale/messages.pot' +print('Generate template') +os.system(cmd) + +os.chdir('electrum') + +crowdin_identifier = 'electrum' +crowdin_file_name = 'files[electrum-client/messages.pot]' +locale_file_name = 'locale/messages.pot' +crowdin_api_key = None + +filename = os.path.expanduser('~/.crowdin_api_key') +if os.path.exists(filename): + with open(filename) as f: + crowdin_api_key = f.read().strip() + +if "crowdin_api_key" in os.environ: + crowdin_api_key = os.environ["crowdin_api_key"] + +if crowdin_api_key: + # Push to Crowdin + print('Push to Crowdin') + url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key) + with open(locale_file_name, 'rb') as f: + files = {crowdin_file_name: f} + response = requests.request('POST', url, files=files) + print("", "update-file:", "-"*20, response.text, "-"*20, sep="\n") + # Build translations + print('Build translations') + response = requests.request('GET', 'https://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key) + print("", "export:", "-" * 20, response.text, "-" * 20, sep="\n") +