diff --git a/.cirrus.yml b/.cirrus.yml index 2064b93d4..bbd06bf52 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -64,7 +64,7 @@ task: fingerprint_script: echo Locale && echo $ELECTRUM_IMAGE && cat $ELECTRUM_REQUIREMENTS_CI install_script: - apt-get update - - apt-get -y install gettext + - apt-get -y install gettext qttools5-dev-tools - pip install -r $ELECTRUM_REQUIREMENTS_CI - pip install requests locale_script: diff --git a/README.md b/README.md index 4cbaf6d22..683c4ce8e 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ $ python3 -m pip install --user -e . Create translations (optional): ``` -$ sudo apt-get install python-requests gettext qttools5-dev-tools +$ sudo apt-get install python3-requests gettext qttools5-dev-tools $ ./contrib/pull_locale ``` diff --git a/contrib/deterministic-build/electrum-locale b/contrib/deterministic-build/electrum-locale index 4941c1a92..a87f9a043 160000 --- a/contrib/deterministic-build/electrum-locale +++ b/contrib/deterministic-build/electrum-locale @@ -1 +1 @@ -Subproject commit 4941c1a92925f198cb0e8d4334692a09917ffc20 +Subproject commit a87f9a04302682bc23ce13bfa6672c12f0de798f diff --git a/contrib/pull_locale b/contrib/pull_locale index 9f2b8536b..8d056e022 100755 --- a/contrib/pull_locale +++ b/contrib/pull_locale @@ -1,89 +1,21 @@ #!/usr/bin/env python3 import os import subprocess -import io -import zipfile -import sys +import importlib.util -try: - import requests -except ImportError as e: - sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install '") +project_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +locale_path = os.path.join(project_root, "electrum", "locale") -os.chdir(os.path.dirname(os.path.realpath(__file__))) -os.chdir('..') +# download latest .po files from crowdin +locale_update = os.path.join(project_root, "contrib", "deterministic-build", "electrum-locale", "update.py") +assert os.path.exists(locale_update) +# load update.py; needlessly complicated alternative to "imp.load_source": +lu_spec = importlib.util.spec_from_file_location('update', locale_update) +lu_module = importlib.util.module_from_spec(lu_spec) +lu_spec.loader.exec_module(lu_module) -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=messages.pot' -print('Generate template') -os.system(cmd) - -# add QML translations -cmd = "find electrum/gui/qml -type f -name '*.qml'" - -files = subprocess.check_output(cmd, shell=True) - -with open("qml.lst", "wb") as f: - f.write(files) - -print("Found {} QML files to translate".format(len(files.splitlines()))) - -cmd = "lupdate @qml.lst -ts qml.ts" -print('Collecting strings') -os.system(cmd) - -cmd = "lconvert -of po -o qml.pot qml.ts" -print('Convert to gettext') -os.system(cmd) - -cmd = "msgcat -u -o electrum/locale/messages.pot messages.pot qml.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)) +lu_module.pull_locale(locale_path) # 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) +subprocess.check_output([f"{project_root}/contrib/build_locale.sh", locale_path, locale_path]) + diff --git a/contrib/push_locale b/contrib/push_locale index 6ccfa694a..487058e1b 100755 --- a/contrib/push_locale +++ b/contrib/push_locale @@ -6,13 +6,14 @@ import sys try: import requests except ImportError as e: - sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install '") + sys.exit(f"Error: {str(e)}. Try 'python3 -m pip install --user '") -os.chdir(os.path.dirname(os.path.realpath(__file__))) -os.chdir('..') -cmd = "find electrum -type f -name '*.py' -o -name '*.kv'" +project_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + +os.chdir(project_root) +cmd = "find electrum -type f -name '*.py' -o -name '*.kv'" files = subprocess.check_output(cmd, shell=True) with open("app.fil", "wb") as f: @@ -24,10 +25,33 @@ print("Found {} files to translate".format(len(files.splitlines()))) if not os.path.exists('electrum/locale'): os.mkdir('electrum/locale') print('Generating template...') -cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --output=electrum/locale/messages.pot' +cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --output=messages.pot' +subprocess.check_output(cmd, shell=True) + + +# add QML translations +cmd = "find electrum/gui/qml -type f -name '*.qml'" +files = subprocess.check_output(cmd, shell=True) + +with open("qml.lst", "wb") as f: + f.write(files) + +print("Found {} QML files to translate".format(len(files.splitlines()))) + +cmd = "lupdate @qml.lst -ts qml.ts" +print('Collecting strings') +subprocess.check_output(cmd, shell=True) + +cmd = "lconvert -of po -o qml.pot qml.ts" +print('Convert to gettext') +subprocess.check_output(cmd, shell=True) + +cmd = "msgcat -u -o electrum/locale/messages.pot messages.pot qml.pot" +print('Generate template') subprocess.check_output(cmd, shell=True) -os.chdir('electrum') + +os.chdir(os.path.join(project_root, "electrum")) crowdin_api_key = None diff --git a/contrib/release.sh b/contrib/release.sh index cb325bdea..34d1fa3ab 100755 --- a/contrib/release.sh +++ b/contrib/release.sh @@ -19,7 +19,7 @@ # # Note: steps before doing a new release: # - update locale: -# 1. cd /opt/electrum-locale && ./update && git push +# 1. cd /opt/electrum-locale && ./update.py && git push # 2. cd to the submodule dir, and git pull # 3. cd .. && git push # - update RELEASE-NOTES and version.py