-
Notifications
You must be signed in to change notification settings - Fork 13
/
pull_translations.py
61 lines (47 loc) · 2.14 KB
/
pull_translations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import sys
import json
import requests
from transifex.api import TransifexAPI
pathname = os.path.dirname(sys.argv[0])
local_dir = os.path.abspath(pathname)
username = os.getenv('TRANSIFEX_USERNAME')
password = os.getenv('TRANSIFEX_PASSWORD')
t = TransifexAPI(username, password, 'http://www.transifex.com')
def get_statistics(project, resource):
url = 'https://www.transifex.com/api/2/project/{}/resource/{}/stats/'.format(
project, resource
)
response = requests.get(url, auth=(username, password))
return json.loads(response.content)
def printProgress (iteration, total, prefix = '', suffix = '', decimals = 2, barLength = 100):
filledLength = int(round(barLength * iteration / float(total)))
percents = round(100.00 * (iteration / float(total)), decimals)
bar = '#' * filledLength + '-' * (barLength - filledLength)
return '%s [%s] %s%s %s' % (prefix, bar, percents, '%', suffix)
resources = t.list_resources('mifm')
progress_data = 'Language translation progress:\n'
for resource in resources:
fname = resource['name']
fnamep = fname.split('.')
languages = t.list_languages('mifm', resource['slug'])
statistics = get_statistics('mifm', resource['slug'])
progress_data += '-'*50
progress_data += '\n'
progress_data += ' {}\n'.format(resource['name'])
progress_data += '-'*50
progress_data += '\n'
for lang_name in languages:
real_name = '{}_{}.xml'.format(fnamep[0], lang_name)
# print t.list_translation_strings('mifm', resource['slug'], lang_name)
print t.get_translation('mifm', resource['slug'], lang_name, '{}/translation/{}'.format(local_dir, real_name))
for lang, sdict in statistics.iteritems():
completed = sdict.get('completed', '0%')
completed_int = int(completed[:-1])
progress_data += 'Language Code: {}\n'.format(lang)
progress = printProgress(completed_int, 100, prefix = 'Progress:', suffix = 'Complete', barLength = 50)
progress_data += '{}\n'.format(progress)
progress_data += '\n\n'
fh = open('translation_statistics.txt', 'w')
fh.write(progress_data)
fh.close()