URI: 
       tpull_locale - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
       tpull_locale (1885B)
       ---
            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 
           38 # Download & unzip
           39 print('Download translations')
           40 s = requests.request('GET', 'https://crowdin.com/backend/download/project/' + crowdin_identifier + '.zip').content
           41 zfobj = zipfile.ZipFile(io.BytesIO(s))
           42 
           43 print('Unzip translations')
           44 for name in zfobj.namelist():
           45     if not name.startswith('electrum-client/locale'):
           46         continue
           47     if name.endswith('/'):
           48         if not os.path.exists(name[16:]):
           49             os.mkdir(name[16:])
           50     else:
           51         with open(name[16:], 'wb') as output:
           52             output.write(zfobj.read(name))
           53 
           54 # Convert .po to .mo
           55 print('Installing')
           56 for lang in os.listdir('locale'):
           57     if lang.startswith('messages'):
           58         continue
           59     # Check LC_MESSAGES folder
           60     mo_dir = 'locale/%s/LC_MESSAGES' % lang
           61     if not os.path.exists(mo_dir):
           62         os.mkdir(mo_dir)
           63     cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang)
           64     print('Installing', lang)
           65     os.system(cmd)