X-Git-Url: https://git.novaco.in/?p=electrum-nvc.git;a=blobdiff_plain;f=mki18n.py;h=1bbd0fa294aa0a3654e709d0527d79ad0a026f56;hp=a4f8b4dd6463949fff4324fa20e378174504abf6;hb=HEAD;hpb=029e7b1edca484c1d13282f00bddf2c79b64dfcf diff --git a/mki18n.py b/mki18n.py index a4f8b4d..1bbd0fa 100755 --- a/mki18n.py +++ b/mki18n.py @@ -1,55 +1,63 @@ #!/usr/bin/python +from StringIO import StringIO +import urllib2, os, zipfile, pycurl -import urllib2, os - -url = "https://en.bitcoin.it/wiki/Electrum/Translation?action=raw" -f = urllib2.urlopen(url) -lines = f.readlines() -dicts = {} -message = None -for line in lines: - l = line.strip() - if not l: continue - if l[0] != '*': continue - if l[0:2] == '**': - lang, translation = l.split(':') - lang = lang[2:] - if dicts.get(lang) is None: dicts[lang] = {} - dicts[lang][message] = translation - else: - message = l[1:] - -#print dicts - -if not os.path.exists('locale'): - os.mkdir('locale') - +crowdin_identifier = 'electrum' +crowdin_file_name = 'electrum-client/messages.pot' +locale_file_name = 'locale/messages.pot' -cmd = 'xgettext -s --no-wrap -f app.fil --output=locale/messages.pot' -print cmd -os.system(cmd) +if os.path.exists('contrib/crowdin_api_key.txt'): + crowdin_api_key = open('contrib/crowdin_api_key.txt').read() -f = open('locale/messages.pot','r') -s = f.read() -f.close() -s = s.replace('CHARSET', 'utf-8') + # Generate fresh translation template + if not os.path.exists('locale'): + os.mkdir('locale') -for lang, strings in dicts.items(): - ss = s[:] - for k,v in strings.items(): - ss = ss.replace("msgid \"%s\"\nmsgstr \"\""%k,"msgid \"%s\"\nmsgstr \"%s\""%(k,v)) - f = open('locale/electrum_%s.po'%lang,'w') - f.write(ss) - f.close() - - if not os.path.exists('locale/'+lang): - os.mkdir('locale/'+lang) + cmd = 'xgettext -s --no-wrap -f app.fil --output=locale/messages.pot' + print 'Generate template' + os.system(cmd) - mo_dir = "locale/%s/LC_MESSAGES" % lang + # Push to Crowdin + print 'Push to Crowdin' + url = ('http://api.crowdin.net/api/project/' + crowdin_identifier + '/update-file?key=' + crowdin_api_key) + + c = pycurl.Curl() + c.setopt(c.URL, url) + 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 + print 'Build translations' + response = urllib2.urlopen('http://api.crowdin.net/api/project/' + crowdin_identifier + '/export?key=' + crowdin_api_key).read() + print response + +# Download & unzip +print 'Download translations' +zfobj = zipfile.ZipFile(StringIO(urllib2.urlopen('http://crowdin.net/download/project/' + crowdin_identifier + '.zip').read())) + +print 'Unzip translations' +for name in zfobj.namelist(): + if not name.startswith('electrum-client/locale'): + continue + if name.endswith('/'): + if not os.path.exists(name[16:]): + os.mkdir(name[16:]) + else: + output = open(name[16:],'w') + output.write(zfobj.read(name)) + output.close() + +# Convert .po to .mo +print 'Installing' +for lang in os.listdir('./locale'): + if lang.startswith('messages'): + continue + # Check LC_MESSAGES folder + mo_dir = 'locale/%s/LC_MESSAGES' % lang if not os.path.exists(mo_dir): os.mkdir(mo_dir) - - cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/electrum_%s.po"' % (mo_dir,lang) - print cmd + cmd = 'msgfmt --output-file="%s/electrum.mo" "locale/%s/electrum.po"' % (mo_dir,lang) + print 'Installing',lang os.system(cmd) -