-
Notifications
You must be signed in to change notification settings - Fork 44
/
localiser.py
53 lines (44 loc) · 2.3 KB
/
localiser.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
import os
import re
import sys
import tempfile
advancements = {}
for root, dirs, files in os.walk(sys.argv[1]):
for file in files:
if file.endswith('.txt'):
advancementPath = os.path.join(root, file)
transKeyElements = advancementPath.partition('script/')[2].lower().split('/')
transKey = 'advancement'
for element in transKeyElements:
element = element.split('.')[0]
transKey += '.' + element
advancements[advancementPath] = transKey
lang = {}
for advancementPath, advancementTranslationKey in advancements.items():
with tempfile.NamedTemporaryFile(mode="r+") as tempFile:
with open(advancementPath, "r") as advancementFile:
for line in advancementFile:
# if line.startswith("setTitle") and not re.match(".*\"translate\":", line):
# line = line.replace("setTitle", "setTranslatedTitle")
# lang[advancementTranslationKey + ".title"] = line.split('"')[1]
# line = re.sub("\".*\"", "\"" + advancementTranslationKey + ".title" + "\"", line)
if line.startswith("setDescription") and not re.match(".*\"text\":", line):
if not re.match(".*\"translate\":", line):
line = line.replace("setDescription", "setTranslatedDescription")
lang[advancementTranslationKey + ".description"] = line.split('"')[1]
line = re.sub(r"\".*\"", "\"" + advancementTranslationKey + ".description" + "\"", line)
else:
if not "advancement." in line:
lang[advancementTranslationKey + ".description"] = line.split('"')[3]
line = re.sub(
r"\"translate\":\"[^\"]*\"",
"\"translate\":\"{}\"".format(advancementTranslationKey + ".description"),
line
)
tempFile.write(line)
tempFile.seek(0)
with open(advancementPath, 'w', newline="\r\n") as advancementFile:
for line in tempFile:
advancementFile.write(line)
for transKey, localString in lang.items():
print(transKey + "=" + localString)