You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
66 lines
1.8 KiB
7 years ago
|
#!/usr/bin/env python3
|
||
|
import os
|
||
7 years ago
|
import subprocess
|
||
7 years ago
|
import io
|
||
|
import zipfile
|
||
6 years ago
|
import sys
|
||
|
|
||
|
try:
|
||
|
import requests
|
||
|
except ImportError as e:
|
||
|
sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install <module-name>'")
|
||
10 years ago
|
|
||
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||
|
os.chdir('..')
|
||
|
|
||
7 years ago
|
cmd = "find electrum -type f -name '*.py' -o -name '*.kv'"
|
||
7 years ago
|
|
||
|
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())))
|
||
|
|
||
10 years ago
|
# Generate fresh translation template
|
||
7 years ago
|
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'
|
||
7 years ago
|
print('Generate template')
|
||
10 years ago
|
os.system(cmd)
|
||
|
|
||
7 years ago
|
os.chdir('electrum')
|
||
10 years ago
|
|
||
|
crowdin_identifier = 'electrum'
|
||
7 years ago
|
crowdin_file_name = 'files[electrum-client/messages.pot]'
|
||
10 years ago
|
locale_file_name = 'locale/messages.pot'
|
||
|
|
||
|
# Download & unzip
|
||
7 years ago
|
print('Download translations')
|
||
7 years ago
|
s = requests.request('GET', 'https://crowdin.com/backend/download/project/' + crowdin_identifier + '.zip').content
|
||
7 years ago
|
zfobj = zipfile.ZipFile(io.BytesIO(s))
|
||
10 years ago
|
|
||
7 years ago
|
print('Unzip translations')
|
||
10 years ago
|
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:
|
||
7 years ago
|
with open(name[16:], 'wb') as output:
|
||
|
output.write(zfobj.read(name))
|
||
10 years ago
|
|
||
|
# Convert .po to .mo
|
||
7 years ago
|
print('Installing')
|
||
10 years ago
|
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)
|
||
7 years ago
|
print('Installing', lang)
|
||
10 years ago
|
os.system(cmd)
|