forked from shadowsocks/shadowsocks-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
executable file
·86 lines (75 loc) · 2.61 KB
/
translate.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
"""
Copyright (C) 2019 by Max Lv <[email protected]>
Copyright (C) 2019 by Mygod Studio <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Usage: ./translate.py <API token>
Prerequisite: pip install poeditor
See also: https://poeditor.com/docs/languages
"""
import itertools
import multiprocessing
import os
import sys
import threading
from multiprocessing.pool import ThreadPool
from poeditor import POEditorAPI
def main(api_token, project_id, languages, tags, file_path):
client = POEditorAPI(api_token)
# See also: https://github.com/sporteasy/python-poeditor/pull/15
client.FILTER_BY += 'proofread'
done = 0
lock = threading.Lock()
def export_worker(params):
((language_code, language_id), (tag, module)) = params
output = file_path.format(language_id, module)
try:
os.makedirs(os.path.dirname(output))
except FileExistsError:
pass
client.export(project_id, language_code, 'android_strings', 'proofread', tag, output)
with lock:
nonlocal done
done += 1
print("{}/{}: {}".format(done, len(languages) * len(tags), output))
pool = ThreadPool(max(64, multiprocessing.cpu_count()))
pool.map(export_worker, itertools.product(languages.items(), tags.items()))
if __name__ == "__main__":
sys.exit(main(
api_token=sys.argv[1],
project_id='89595',
languages={
# Chinese (simplified)
'zh-CN': 'zh-rCN',
# Chinese (traditional)
'zh-TW': 'zh-rTW',
# French
'fr': 'fr',
# Japanese
'ja': 'ja',
# Korean
'ko': 'ko',
# Persian
'fa': 'fa',
# Russian
'ru': 'ru',
# Spanish
'es': 'es',
# Turkish
'tr': 'tr',
},
tags={
'mobile': 'core',
'plugin': 'plugin',
},
file_path='{1}/src/main/res/values-{0}/strings.xml',
))