6 changed files with 47 additions and 91 deletions
@ -1 +1 @@ |
|||||||
Subproject commit 4941c1a92925f198cb0e8d4334692a09917ffc20 |
Subproject commit a87f9a04302682bc23ce13bfa6672c12f0de798f |
||||||
@ -1,89 +1,21 @@ |
|||||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||||
import os |
import os |
||||||
import subprocess |
import subprocess |
||||||
import io |
import importlib.util |
||||||
import zipfile |
|
||||||
import sys |
|
||||||
|
|
||||||
try: |
project_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
||||||
import requests |
locale_path = os.path.join(project_root, "electrum", "locale") |
||||||
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__))) |
# download latest .po files from crowdin |
||||||
os.chdir('..') |
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'" |
lu_module.pull_locale(locale_path) |
||||||
|
|
||||||
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)) |
|
||||||
|
|
||||||
# Convert .po to .mo |
# Convert .po to .mo |
||||||
print('Installing') |
subprocess.check_output([f"{project_root}/contrib/build_locale.sh", locale_path, locale_path]) |
||||||
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) |
|
||||||
|
|||||||
Loading…
Reference in new issue