electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

push_locale (1877B)


      1 #!/usr/bin/env python3
      2 import os
      3 import subprocess
      4 import io
      5 import zipfile
      6 import sys
      7 
      8 try:
      9     import requests
     10 except ImportError as e:
     11     sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install <module-name>'")
     12 
     13 os.chdir(os.path.dirname(os.path.realpath(__file__)))
     14 os.chdir('..')
     15 
     16 cmd = "find electrum -type f -name '*.py' -o -name '*.kv'"
     17 
     18 files = subprocess.check_output(cmd, shell=True)
     19 
     20 with open("app.fil", "wb") as f:
     21     f.write(files)
     22 
     23 print("Found {} files to translate".format(len(files.splitlines())))
     24 
     25 # Generate fresh translation template
     26 if not os.path.exists('electrum/locale'):
     27     os.mkdir('electrum/locale')
     28 cmd = 'xgettext -s --from-code UTF-8 --language Python --no-wrap -f app.fil --output=electrum/locale/messages.pot'
     29 print('Generate template')
     30 os.system(cmd)
     31 
     32 os.chdir('electrum')
     33 
     34 crowdin_identifier = 'electrum'
     35 crowdin_file_name = 'files[electrum-client/messages.pot]'
     36 locale_file_name = 'locale/messages.pot'
     37 crowdin_api_key = None
     38 
     39 filename = os.path.expanduser('~/.crowdin_api_key')
     40 if os.path.exists(filename):
     41     with open(filename) as f:
     42         crowdin_api_key = f.read().strip()
     43 
     44 if "crowdin_api_key" in os.environ:
     45     crowdin_api_key = os.environ["crowdin_api_key"]
     46 
     47 if crowdin_api_key:
     48     # Push to Crowdin
     49     print('Push to Crowdin')
     50     url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
     51     with open(locale_file_name, 'rb') as f:
     52         files = {crowdin_file_name: f}
     53         response = requests.request('POST', url, files=files)
     54     print("", "update-file:", "-"*20, response.text, "-"*20, sep="\n")
     55     # Build translations
     56     print('Build translations')
     57     response = requests.request('GET', 'https://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key)
     58     print("", "export:", "-" * 20, response.text, "-" * 20, sep="\n")
     59