forked from JustASysAdmin/TheOtherRoles2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringsToJson.py
87 lines (75 loc) · 2.01 KB
/
stringsToJson.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
87
import os
import json
from openpyxl import load_workbook
WORKING_DIR = os.path.dirname(os.path.realpath(__file__))
IN_FILE = os.path.join(WORKING_DIR, "Strings.xlsx")
OUT_FILE = os.path.join(WORKING_DIR, "TheOtherRoles", "Resources", "stringData.json")
def getLanguageId(str):
match str:
case "English":
return 0
case "Latam":
return 1
case "Brazilian":
return 2
case "Portuguese":
return 3
case "Korean":
return 4
case "Russian":
return 5
case "Dutch":
return 6
case "Filipino":
return 7
case "French":
return 8
case "German":
return 9
case "Italian":
return 10
case "Japanese":
return 11
case "Spanish":
return 12
case "SChinese":
return 13
case "TChinese":
return 14
case "Irish":
return 15
return -1
def stringToJson(in_files):
stringData = {}
for filename in in_files:
if not os.path.isfile(filename):
continue
wb = load_workbook(filename, read_only = True)
for s in wb:
headers = []
rows = s.iter_rows(min_col = 1, min_row = 1, max_col = 18, max_row = 1)
for row in rows:
for string in row[2:]:
if string.value:
headers.append(string.value)
rows = s.iter_rows(min_col = 1, min_row = 1, max_col = 18, max_row = None)
for row in rows:
name = f"{row[0].value},{row[1].value}"
if name == "Category,Id":
continue
if not name:
continue
data = {}
for i, string in enumerate(row[2:]):
if string.value:
id = getLanguageId(headers[i])
data[id] = string.value.replace("\r", "").replace("_x000D_", "").replace("\\n", "\n")
if data:
stringData[name] = data
with open(OUT_FILE, "w", newline="\n") as f:
json.dump(stringData, f, indent=4)
if __name__ == "__main__":
in_files = [
os.path.join(WORKING_DIR, "Strings.xlsx")
]
stringToJson(in_files)