forked from Fast0n/xmlTranslate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (30 loc) · 994 Bytes
/
main.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
from translate import Translator
import xml.etree.ElementTree as ET
from time import sleep
import sys
import html
translator = Translator(to_lang=sys.argv[3])
tree = ET.parse(sys.argv[1])
root = tree.getroot()
print(chr(27) + "[2J")
for item in root.iter('string'):
try:
if item.attrib['translatable'] == "false":
exit
except:
translation = translator.translate(item.text)
a = '{} -> {}'.format((item.text), translation)
print(a.encode('ascii', 'xmlcharrefreplace'))
ask = input('Is this a good translation? n[no], q[close]: ')
if ask == "n":
correctTranslation = input('Write the correct translation here: ')
correctTranslation = html.unescape(correctTranslation)
item.text = correctTranslation
elif ask == "q":
sys.exit(0)
else:
item.text = translation
tree.write(sys.argv[2])
sleep(1)
print('- - -')
print("Finish!")