-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.py
78 lines (68 loc) · 3.28 KB
/
import.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
import os
import json
import openpyxl
srcDir = 'data/scenario'
outDir = '../data/scenario'
with open('extracted.json', encoding='utf-8') as f:
extracted = json.load(f)
db: dict[str, dict[str, str]] = {}
wb = openpyxl.load_workbook(R"F:\Downloads\ゆめのおにわでchasing - 文本汉化表.xlsx")
for sheet in wb.worksheets:
if sheet.title != 'Index':
db[sheet.title] = {}
for row in sheet.iter_rows(min_row=2, max_row=sheet.max_row, min_col=2, max_col=3):
if row[0].value:
src = str(row[0].value)
tld = str(row[1].value or '')
db[sheet.title][src] = tld
totalNum = len(db[sheet.title])
translatedNum = len([1 for txt in db[sheet.title] if (db[sheet.title][txt] and db[sheet.title][txt] != '「」')])
print(f'{sheet.title:<30} {translatedNum:>3} / {totalNum:<3} {translatedNum / totalNum * 100:>3.0f}%')
db[sheet.title] = dict(sorted(list(db[sheet.title].items()), key=lambda a: len(a[0]), reverse=True))
diff = (db[sheet.title].keys() - extracted[sheet.title].keys()).union(extracted[sheet.title].keys() - db[sheet.title].keys())
if len(diff) > 0:
print('*** Diff:', diff, '\n')
with open(os.path.join(srcDir, sheet.title), encoding='utf-8') as f:
ks0 = f.read()
ks = ks0
for src in db[sheet.title]:
tld = db[sheet.title][src]
if not src in ks:
raise Exception(src)
if tld:
# if (('「' in src and not '「' in tld) or ('」' in src and not '」' in tld)):
# print(f'Square brackets not added: \n{src}\n{tld}\n')
ks = ks.replace(src, tld)
for name, nameTL in [
('【まどか】', '【圆】'),
('【ほむら】', '【焰】'),
('【さやか】', '【沙耶加】'),
('【杏子】', ''),
('【エイミー】', '【艾米】'),
('【???】', ''),
('【まどか&ほむら】', '【圆&焰】'),
('【詢子】', '【询子】'),
('【マミ】', '【麻美】'),
('【なぎさ】', '【渚】'),
('【??】', ''),
('【マミ&なぎさ】', '【麻美&渚】'),
# ('【ほむら】 ', '【焰】 '),
('【ほむら&マミ&なぎさ】', '【焰&麻美&渚】'),
('【仁美】', ''),
('【先生】', '【老师】'),
('【女子A】', ''),
('【男子B】', ''),
('【一同】', ''),
('【中沢】', '【中泽】'),
('【女子B】', ''),
('【男子A】', ''),
('【マドカ】', '【円】'),
('【まどか&ほむら&マミ】', '【圆&焰&麻美】'),
]:
if nameTL:
ks = ks.replace(name, nameTL)
if ks != ks0:
with open(os.path.join(outDir, sheet.title), 'w', encoding='utf-8') as f:
f.write(ks)
with open(f'translated.json', 'w', encoding='utf-8') as f:
json.dump(db, f, ensure_ascii=False, indent=2)