-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtmaterial.py
66 lines (55 loc) · 1.9 KB
/
gtmaterial.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
import requests
import os
import sys
import json
#put "GregTech.lang" and this script in the same file
auth_key = "api_key" #your api key
target_language = "TR" #languange code
def translate_text(text):
url = "https://api-free.deepl.com/v2/translate"
payload = {
"text": text,
"target_lang": target_language,
"auth_key": auth_key
}
response = requests.post(url, data=payload)
if response.status_code == 200:
translation = response.json()["translations"][0]["text"]
return translation
else:
print("Error:", response.status_code)
def main():
with open('GregTech.lang', 'r', encoding="utf-8") as f:
lines = f.read().splitlines()
properties = []
rest = []
for line in lines:
if line.startswith("}"):
break
split = line.split("=", 1)
if len(split) != 2:
found_material = False
continue
key = split[0].replace('"context": "',"")
s_key = f"gt-lang|{key}"
value = split[1].replace('"','')
if key.startswith(" S:Material"):
properties.append({
'key': s_key,
'original': value,
'translation': translate_text(value),
'stage': 5,
'context': s_key.replace("gt-lang|","") + '=' + value,
})
else:
rest.append(s_key + '=' + value)
with open('gtlang.txt', mode="wt", encoding="utf-8") as f:
for line in properties:
f.write(line['context'] + '\n')
with open('GregTech.lang.json', mode="wt", encoding="utf-8") as f:
json.dump(properties, f, ensure_ascii=False, indent=2)
with open('rest.txt', mode="wt", encoding="utf-8") as f:
for line in rest:
f.write(line + '\n')
if __name__ == '__main__':
main()