move master_private_keys and master_public_keys to NewWallet
[electrum-nvc.git] / mki18n.py
1 #!/usr/bin/python
2 from StringIO import StringIO
3 import urllib2, os, zipfile, pycurl
4
5 crowdin_identifier = 'electrum'
6 crowdin_file_name = 'electrum-client/messages.pot'
7 locale_file_name = 'locale/messages.pot'
8
9 if os.path.exists('contrib/crowdin_api_key.txt'):
10     crowdin_api_key = open('contrib/crowdin_api_key.txt').read()
11
12     # Generate fresh translation template
13     if not os.path.exists('locale'):
14       os.mkdir('locale')
15
16     cmd = 'xgettext -s --no-wrap -f app.fil --output=locale/messages.pot'
17     print 'Generate template'
18     os.system(cmd)
19
20     # Push to Crowdin
21     print 'Push to Crowdin'
22     url = ('http://api.crowdin.net/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key)
23
24     c = pycurl.Curl()
25     c.setopt(c.URL, url)
26     c.setopt(c.POST, 1)
27     fields = [('files[' + crowdin_file_name + ']', (pycurl.FORM_FILE, locale_file_name))]
28     c.setopt(c.HTTPPOST, fields)
29     c.perform()
30
31     # Build translations
32     print 'Build translations'
33     response = urllib2.urlopen('http://api.crowdin.net/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key).read()
34     print response
35
36 # Download & unzip
37 print 'Download translations'
38 zfobj = zipfile.ZipFile(StringIO(urllib2.urlopen('http://crowdin.net/download/project/' + crowdin_identifier + '.zip').read()))
39
40 print 'Unzip translations'
41 for name in zfobj.namelist():
42     if not name.startswith('electrum-client/locale'):
43         continue
44     if name.endswith('/'):
45         if not os.path.exists(name[16:]):
46             os.mkdir(name[16:])
47     else:
48         output = open(name[16:],'w')
49         output.write(zfobj.read(name))
50         output.close()
51
52 # Convert .po to .mo
53 print 'Installing'
54 for lang in os.listdir('./locale'):
55     if lang.startswith('messages'):
56         continue
57     # Check LC_MESSAGES folder
58     mo_dir = 'locale/%s/LC_MESSAGES' % lang
59     if not os.path.exists(mo_dir):
60         os.mkdir(mo_dir)
61     cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang)
62     print 'Installing',lang
63     os.system(cmd)