-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransTool.py
55 lines (50 loc) · 2.17 KB
/
TransTool.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
import os
def readFile(path, source, target, isALL):
count = 0
if isALL:
file = open(path + 'new\\' + "new_" + target,
mode='w', encoding="UTF8")
else:
file = open(path + "new_" + target, mode='w', encoding="UTF8")
with open(path + source, encoding="UTF8") as sfile:
for lines in sfile.readlines():
if '=' in lines:
if lines.split("=")[0] in target_dic:
if "\n" in target_dic[lines.split("=")[0]]:
file.writelines(lines.split(
"=")[0] + "=" + target_dic[lines.split("=")[0]])
else:
file.writelines(lines.split(
"=")[0] + "=" + target_dic[lines.split("=")[0]] + "\n")
else:
file.writelines(lines.replace("\n", "") + "#WTT" + "\n")
count += 1
else:
file.writelines(lines)
file.close()
print("Create a new file named " + ("new_" + target))
print("There are ", count, "lines wait to trans, mark with #WTT")
if __name__ == "__main__":
target_dic = {}
path = input("Please input path of lang \n") + "\\"
source = input("Please input the souse lang(without .lang)\n") + ".lang"
target = input(
"Please input the target lang(without .lang) or just input all for others\n") + ".lang"
if 'all' in target:
if not os.path.exists(path + 'new'):
os.mkdir(path + 'new')
for lang in os.listdir(path):
if source in lang or os.path.isdir(path + lang):
continue
target_dic = {}
with open(path + lang, encoding="UTF8") as file:
for lines in file.readlines():
if '=' in lines:
target_dic[lines.split("=")[0]] = lines.split("=")[1]
readFile(path, source, lang, True)
else:
with open(path + target, encoding="UTF8") as file:
for lines in file.readlines():
if '=' in lines:
target_dic[lines.split("=")[0]] = lines.split("=")[1]
readFile(path, source, target, False)