-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate_title.py
executable file
·86 lines (75 loc) · 2.28 KB
/
translate_title.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
from json import dump, load
from os.path import isfile
import sys
class colors:
BOLD = "\033[1m"
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
END = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def save(obj, f):
f = open(f, "w")
dump(obj, f, sort_keys=True, indent=4)
def translate(translations, key, move):
print()
print("==============================================")
print("ID: ", key)
print("Beschreibung:", move["description"])
print("----------------------------------------------")
print("--------- 'jump' zum Überspringen ------------")
print("----------------------------------------------")
print("Text: '" +
colors.BOLD +
move["name"] +
colors.END +
"'")
name = input("Übersetzung: ")
print("==============================================")
if name.lower() == "jump":
return True
if name:
translations[key] = name
return True
return False
data_file = open("data.json", "r")
data = load(data_file)
translations = {}
if isfile("title_translations.json"):
in_file = open("title_translations.json", "r")
translations = load(in_file)
out_file = "title_translations.json"
# Translate basic moves
moves = data["basic_moves"]
for move in moves:
if not move["key"] in translations:
success = translate(translations, move["key"], move)
save(translations, out_file)
if not success:
sys.exit()
# Translate special moves
moves = data["special_moves"]
for move in moves:
if not move["key"] in translations:
success = translate(translations, move["key"], move)
save(translations, out_file)
if not success:
sys.exit()
save(translations, out_file)
# Reload moves to fix dublication bug
translations = {}
if isfile("title_translations.json"):
in_file = open("title_translations.json", "r")
translations = load(in_file)
# Translate all remaining moves
moves = data["moves"]
for key, move in moves.items():
if not key in translations:
success = translate(translations, key, move)
save(translations, out_file)
if not success:
sys.exit()