Files
pallectrum/contrib/push_locale

60 lines
1.8 KiB
Plaintext
Raw Normal View History

2017-08-27 08:01:12 +02:00
#!/usr/bin/env python3
import os
2018-03-09 19:13:42 +01:00
import subprocess
2017-08-27 08:01:12 +02:00
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>'")
2015-02-21 12:41:52 +01:00
os.chdir(os.path.dirname(os.path.realpath(__file__)))
os.chdir('..')
cmd = "find electrum -type f -name '*.py' -o -name '*.kv'"
2018-03-09 19:13:42 +01:00
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())))
2015-02-21 12:41:52 +01:00
# 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'
2017-08-27 08:01:12 +02:00
print('Generate template')
2015-02-21 12:41:52 +01:00
os.system(cmd)
os.chdir('electrum')
2015-02-21 12:41:52 +01:00
crowdin_identifier = 'electrum'
2018-03-12 16:58:05 +01:00
crowdin_file_name = 'files[electrum-client/messages.pot]'
2015-02-21 12:41:52 +01:00
locale_file_name = 'locale/messages.pot'
2017-05-18 21:04:09 +02:00
crowdin_api_key = None
2017-08-27 08:01:12 +02:00
2018-03-12 16:58:05 +01:00
filename = os.path.expanduser('~/.crowdin_api_key')
2017-08-27 08:01:12 +02:00
if os.path.exists(filename):
2017-11-12 14:33:46 +01:00
with open(filename) as f:
crowdin_api_key = f.read().strip()
2017-08-27 08:01:12 +02:00
2017-05-18 21:04:09 +02:00
if "crowdin_api_key" in os.environ:
crowdin_api_key = os.environ["crowdin_api_key"]
2017-08-27 08:01:12 +02:00
2017-05-18 21:04:09 +02:00
if crowdin_api_key:
2015-02-21 12:41:52 +01:00
# Push to Crowdin
2017-08-27 08:01:12 +02:00
print('Push to Crowdin')
2016-08-02 09:53:28 +02:00
url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
2018-03-12 16:58:05 +01:00
with open(locale_file_name, 'rb') as f:
2017-11-12 14:33:46 +01:00
files = {crowdin_file_name: f}
2018-03-12 16:58:05 +01:00
response = requests.request('POST', url, files=files)
print("", "update-file:", "-"*20, response.text, "-"*20, sep="\n")
2015-02-21 12:41:52 +01:00
# Build translations
2017-08-27 08:01:12 +02:00
print('Build translations')
2018-03-12 16:58:05 +01:00
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")
2015-02-21 12:41:52 +01:00