-
Notifications
You must be signed in to change notification settings - Fork 3
/
fix_var_types.py
56 lines (39 loc) · 1.55 KB
/
fix_var_types.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
import io
import re
_variables_ = "variables"
def xml_to_dict(file):
entries = []
for line in file.readlines():
if "entry" in line:
original = re.search(r'(?<=original=")[^"]*(?=")', line).group(0).replace("&", "&").replace(""", '"')
translated = re.search(r'(?<=translated=")[^"]*(?=")', line).group(0).replace("&", "&")
entries.append((original, translated))
return entries
def read_xml_files():
xml_dict = {
_variables_: {},
}
variables_entries = xml_to_dict(io.open("xml/variables.xml", 'r', encoding="utf-8"))
for entry in variables_entries:
xml_dict[_variables_][entry[0]] = entry[1]
return xml_dict
def write_xml(data_type):
global xml
xml_file = io.open("xml/"+data_type+".xml", 'w', encoding="utf-8")
xml_file.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
xml_file.write('<dictionary>\n')
for original, translated in xml[data_type].items():
xml_file.write("\t<entry original=\"" + original.replace("&", "&").replace('"', """) + "\" translated=\"" + translated.replace("&", "&") + "\"/>\n")
xml_file.write('</dictionary>')
xml = read_xml_files()
values = {
_variables_: {},
}
for ori, tran in xml[_variables_].items():
if ori[0] == '$' and tran[0] != '$':
print(ori, tran, sep=": ")
xml[_variables_][ori] = '$' + tran
elif ori[0] != '$' and tran[0] == '$':
print(ori, tran, sep=": ")
xml[_variables_][ori] = tran[1:]
write_xml(_variables_)