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.
60 lines
1.8 KiB
60 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'
|
||
8 years ago
|
crowdin_api_key = None
|
||
7 years ago
|
|
||
7 years ago
|
filename = os.path.expanduser('~/.crowdin_api_key')
|
||
7 years ago
|
if os.path.exists(filename):
|
||
7 years ago
|
with open(filename) as f:
|
||
|
crowdin_api_key = f.read().strip()
|
||
7 years ago
|
|
||
8 years ago
|
if "crowdin_api_key" in os.environ:
|
||
|
crowdin_api_key = os.environ["crowdin_api_key"]
|
||
7 years ago
|
|
||
8 years ago
|
if crowdin_api_key:
|
||
10 years ago
|
# Push to Crowdin
|
||
7 years ago
|
print('Push to Crowdin')
|
||
9 years ago
|
url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
|
||
7 years ago
|
with open(locale_file_name, 'rb') as f:
|
||
7 years ago
|
files = {crowdin_file_name: f}
|
||
7 years ago
|
response = requests.request('POST', url, files=files)
|
||
|
print("", "update-file:", "-"*20, response.text, "-"*20, sep="\n")
|
||
10 years ago
|
# Build translations
|
||
7 years ago
|
print('Build translations')
|
||
7 years ago
|
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")
|
||
10 years ago
|
|