-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
28 lines (24 loc) · 919 Bytes
/
translate.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
import json
import os.path
import sys
from utils import read_names, read_descriptions
def main(file_name, translate_type):
names = read_names(os.path.join("lang/pl", translate_type))
desc = read_descriptions(f"lang/pl/{translate_type}_desc")
with open(file_name) as plik:
for linia in plik.readlines():
a = json.loads(linia)
try:
translated_name = names[a["name"]]
except KeyError:
translated_name = a["name"]
try:
translated_desc = desc[a["name"]]
except KeyError:
translated_desc = a["system"]["description"]["value"]
a["name"] = translated_name
a["system"]["description"]["value"] = translated_desc
print(json.dumps(a, ensure_ascii=False))
if __name__ == "__main__":
if len(sys.argv) > 2:
main(sys.argv[1], sys.argv[2])