forked from dwing4g/tes3-chinese-translation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterms_split.lua
More file actions
226 lines (220 loc) · 5.24 KB
/
terms_split.lua
File metadata and controls
226 lines (220 loc) · 5.24 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
-- luajit terms_split.lua terms.csv terms_split.csv
-- luajit terms_split.lua _.cel cel_split.csv
-- xxx, yyy, zzz XXX,YYY,ZZZ
-- xxx yyy,XXX·YYY
-- luajit terms_split.lua Morrowind.cel ~$cel_split.csv
-- luajit terms_split.lua ~$ext2m\terms.csv ~$ext2m\terms_split.csv
-- luajit terms_split.lua ~$ext2t\terms.csv ~$ext2t\terms_split.csv
-- luajit terms_split.lua ~$ext2b\terms.csv ~$ext2b\terms_split.csv
-- luajit terms_split.lua TamrielRebuilt\TR_Mainland.cel TamrielRebuilt\~$cel_split.csv
local cel = arg[1]:find "%.cel$"
if not cel and not arg[1]:find "%.csv$" then
error("ERROR: unknown format: " .. arg[1])
end
local f = io.open(arg[2], "wb")
local function write(k, v, c)
if k:find ',' or v:find ',' or c:find ',' or
k:find '^"' or v:find '^"' or c:find '^"' then
f:write('"', k:gsub('"', '""'), '","', v:gsub('"', '""'), '","', c:gsub('"', '""'), '"\n')
else
f:write(k, ',', v, ',', c, '\n')
end
end
local lineId = 0
local addIgnored = {
Armory = true,
Asharapli = true,
Axe = true,
Blessing = true,
Chambers = true,
Drarayne = true,
Favani = true,
Gift = true,
Journal = true,
Rest = true,
Ring = true,
Robe = true,
Salen = true,
Shield = true,
Skirt = true,
Spite = true,
Staff = true,
Tale = true,
Tower = true,
Uleni = true,
Wake = true,
}
local t = {}
local tc = {}
local function add(k, v, c)
k = k:gsub("^%s+", ""):gsub("%s+$", "")
v = v:gsub("^%s+", ""):gsub("%s+$", "")
if k ~= "" and v ~= "" then
if t[k] then
if t[k] ~= v then
if tc[k] == c and not addIgnored[k] then
error("ERROR(" .. lineId .. "): duplicated k=" .. k .. ", v=" .. t[k] .. " or " .. v .. ", c=" .. c)
else
t[k] = v
tc[k] = c
write(k, v, c)
end
elseif tc[k] ~= c then
tc[k] = c
write(k, v, c)
end
else
t[k] = v
tc[k] = c
write(k, v, c)
end
else
error("ERROR(" .. lineId .. "): empty k=" .. k .. " or v=" .. v)
end
end
local subIgnored = {
Ancestor = true,
Apprentice = true,
Arrille = true,
Azura = true,
Bungler = true,
Duke = true,
Erna = true, -- 厄娜给...的...
Factor = true,
Father = true,
Fatleg = true,
Fighters = true,
God = true,
Gondolier = true,
Governor = true,
Grandmaster = true,
GrandMaster = true,
Herder = true,
Journeyman = true,
King = true,
Lady = true,
Lizard = true,
Lord = true,
Mages = true,
Master = true,
Miner = true,
Necromancer = true,
Queen = true,
Saint = true,
SecretMaster = true,
Shalk = true,
Shara = true, -- 人名/地名不同
Slave = true,
Stahlman = true,
Watcher = true,
Wizard = true,
["Apprentice's Armorer"] = true,
["Arena Fighter"] = true,
["GrandMaster's Armorer"] = true,
["Her Hand"] = true,
["Journeyman's Armorer"] = true,
["Lower Queen"] = true,
["Master's Armorer"] = true,
["Redoran Watchman"] = true,
["Secret Master"] = true,
["Sewers: Thieves"] = true,
["Sewers: Uriel"] = true,
["The Lizard"] = true,
["The Warrior"] = true,
["Upper Queen"] = true,
}
local function addSub(line, k, v, c)
k = k:gsub("^%s+", ""):gsub("%s+$", "")
v = v:gsub("^%s+", ""):gsub("%s+$", ""):gsub("^《", ""):gsub("》$", "")
local k1, k2 = k:match "^(%a%S*)'s? (%a.*)$"
if k1 and not subIgnored[k1] then
local v1, v2 = v:match "^(...-)的(.+)$"
if not v1 then
v1, v2 = v:match "^(...-)之(.+)$"
if not v1 then
error("ERROR(" .. lineId .. "): unmatched line: " .. line)
end
end
add(k1, v1, c)
add(k2, v2, c)
else
local k4, k1, k2, k3 = k:match "^((%a%S*) (%a%S*))'s? (%a.*)$"
if k1 and not subIgnored[k4] then
local v4, v3 = v:match "^(...-)的(.+)$"
if not v4 then
v4, v3 = v:match "^(...-)之(.+)$"
if not v4 then
error("ERROR(" .. lineId .. "): unmatched line: " .. line)
end
end
local v1, v2 = v4:match "^(...-)·(.+)$"
if v1 then
add(k1, v1, c)
add(k2, v2, c)
else
add(k4, v4, c)
end
add(k3, v3, c)
else
local k1, k2 = k:match "^(%a%S*) (%a%S*)$"
local v1, v2 = v:match "^(...-)·(.+)$"
if k1 and v1 then
add(k1, v1, c)
add(k2, v2, c)
end
end
end
end
for line in io.lines(arg[1]) do
lineId = lineId + 1
if cel then
local k, v = line:match "^(.+)\t(.+)$"
if not k then
error("ERROR(" .. lineId .. "): unknown line: " .. line)
end
local k1, k2, k3 = k:match "^([^,]+),([^,]+),([^,]+)$"
if k1 then
local v1, v2, v3 = v:match "^([^,]+),([^,]+),([^,]+)$"
if not v1 then
error("ERROR(" .. lineId .. "): unmatched line: " .. line)
end
add(k1, v1, "CEL")
add(k2, v2, "CEL")
add(k3, v3, "CEL")
addSub(line, k1, v1, "CEL")
addSub(line, k2, v2, "CEL")
addSub(line, k3, v3, "CEL")
else
k1, k2 = k:match "^([^,]+),([^,]+)$"
if k1 then
local v1, v2 = v:match "^([^,]+),([^,]+)$"
if not v1 then
error("ERROR(" .. lineId .. "): unmatched line: " .. line)
end
add(k1, v1, "CEL")
add(k2, v2, "CEL")
addSub(line, k1, v1, "CEL")
addSub(line, k2, v2, "CEL")
else
add(k, v, "CEL")
addSub(line, k, v, "CEL")
end
end
else
local k, v, c = line:match '^"(..-)","(..-)","(.*)"$'
if k then
k = k:gsub('""', '"')
v = v:gsub('""', '"')
c = c:gsub('""', '"')
else
k, v, c = line:match '^([^,]+),([^,]+),([^,]*)$'
if not k then
error("ERROR(" .. lineId .. "): unknown line: " .. line)
end
end
add(k, v, c)
addSub(line, k, v, c)
end
end
f:close()
print "DONE!"