mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 02:05:19 +00:00
migrate make_locale to python3
This commit is contained in:
parent
837f04a225
commit
9ee10ab3e1
1 changed files with 23 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
from StringIO import StringIO
|
import os
|
||||||
import os, zipfile, pycurl
|
import io
|
||||||
|
import zipfile
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
@ -10,7 +11,7 @@ os.chdir('..')
|
||||||
if not os.path.exists('lib/locale'):
|
if not os.path.exists('lib/locale'):
|
||||||
os.mkdir('lib/locale')
|
os.mkdir('lib/locale')
|
||||||
cmd = 'xgettext -s --no-wrap -f app.fil --output=lib/locale/messages.pot'
|
cmd = 'xgettext -s --no-wrap -f app.fil --output=lib/locale/messages.pot'
|
||||||
print 'Generate template'
|
print('Generate template')
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
|
|
||||||
os.chdir('lib')
|
os.chdir('lib')
|
||||||
|
@ -18,32 +19,32 @@ os.chdir('lib')
|
||||||
crowdin_identifier = 'electrum'
|
crowdin_identifier = 'electrum'
|
||||||
crowdin_file_name = 'electrum-client/messages.pot'
|
crowdin_file_name = 'electrum-client/messages.pot'
|
||||||
locale_file_name = 'locale/messages.pot'
|
locale_file_name = 'locale/messages.pot'
|
||||||
|
|
||||||
crowdin_api_key = None
|
crowdin_api_key = None
|
||||||
if os.path.exists('../contrib/crowdin_api_key.txt'):
|
|
||||||
crowdin_api_key = open('../contrib/crowdin_api_key.txt').read().strip()
|
filename = '~/.crowdin_api_key'
|
||||||
|
if os.path.exists(filename):
|
||||||
|
crowdin_api_key = open(filename).read().strip()
|
||||||
|
|
||||||
if "crowdin_api_key" in os.environ:
|
if "crowdin_api_key" in os.environ:
|
||||||
crowdin_api_key = os.environ["crowdin_api_key"]
|
crowdin_api_key = os.environ["crowdin_api_key"]
|
||||||
|
|
||||||
if crowdin_api_key:
|
if crowdin_api_key:
|
||||||
# Push to Crowdin
|
# Push to Crowdin
|
||||||
print 'Push to Crowdin'
|
print('Push to Crowdin')
|
||||||
url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
|
url = ('https://api.crowdin.com/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
|
||||||
c = pycurl.Curl()
|
files = {crowdin_file_name: open(locale_file_name,'rb')}
|
||||||
c.setopt(c.URL, url)
|
requests.request('POST', url, files=files)
|
||||||
c.setopt(c.POST, 1)
|
|
||||||
fields = [('files[' + crowdin_file_name + ']', (pycurl.FORM_FILE, locale_file_name))]
|
|
||||||
c.setopt(c.HTTPPOST, fields)
|
|
||||||
c.perform()
|
|
||||||
# Build translations
|
# Build translations
|
||||||
print 'Build translations'
|
print('Build translations')
|
||||||
response = requests.request('GET', 'http://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key).content
|
response = requests.request('GET', 'http://api.crowdin.com/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key).content
|
||||||
print response
|
print(response)
|
||||||
|
|
||||||
# Download & unzip
|
# Download & unzip
|
||||||
print 'Download translations'
|
print('Download translations')
|
||||||
zfobj = zipfile.ZipFile(StringIO(requests.request('GET', 'http://crowdin.com/download/project/' + crowdin_identifier + '.zip').content))
|
s = requests.request('GET', 'http://crowdin.com/download/project/' + crowdin_identifier + '.zip').content
|
||||||
|
zfobj = zipfile.ZipFile(io.BytesIO(s))
|
||||||
|
|
||||||
print 'Unzip translations'
|
print('Unzip translations')
|
||||||
for name in zfobj.namelist():
|
for name in zfobj.namelist():
|
||||||
if not name.startswith('electrum-client/locale'):
|
if not name.startswith('electrum-client/locale'):
|
||||||
continue
|
continue
|
||||||
|
@ -51,12 +52,12 @@ for name in zfobj.namelist():
|
||||||
if not os.path.exists(name[16:]):
|
if not os.path.exists(name[16:]):
|
||||||
os.mkdir(name[16:])
|
os.mkdir(name[16:])
|
||||||
else:
|
else:
|
||||||
output = open(name[16:],'w')
|
output = open(name[16:], 'wb')
|
||||||
output.write(zfobj.read(name))
|
output.write(zfobj.read(name))
|
||||||
output.close()
|
output.close()
|
||||||
|
|
||||||
# Convert .po to .mo
|
# Convert .po to .mo
|
||||||
print 'Installing'
|
print('Installing')
|
||||||
for lang in os.listdir('locale'):
|
for lang in os.listdir('locale'):
|
||||||
if lang.startswith('messages'):
|
if lang.startswith('messages'):
|
||||||
continue
|
continue
|
||||||
|
@ -65,5 +66,5 @@ for lang in os.listdir('locale'):
|
||||||
if not os.path.exists(mo_dir):
|
if not os.path.exists(mo_dir):
|
||||||
os.mkdir(mo_dir)
|
os.mkdir(mo_dir)
|
||||||
cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang)
|
cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang)
|
||||||
print 'Installing',lang
|
print('Installing', lang)
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
|
|
Loading…
Add table
Reference in a new issue