-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpack.lua
44 lines (38 loc) · 836 Bytes
/
pack.lua
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
local xml = require "xml"
local cache = {}
local function read(tag, root)
if cache[tag] then
return cache[tag]
end
local f = assert(io.open(root.."/"..tag..".txt"))
local t = xml.collect(f:read"a")
f:close()
local r = {}
for _,v in ipairs(t) do
r[v.xml] = v[1]
end
cache[tag] = r
return r
end
local function replace(filename)
return function(s)
local index, tag = s:match("(.*)%.(%w+)$")
local trans = read(index, filename)
local text = trans["c"..tag]
if text == nil or text == "" then
return trans[tag]
else
return text
end
end
end
local function main(filename)
local f = assert(io.open(filename .. ".xml"))
local s = f:read "a"
f:close()
local s = string.gsub(s, "%$([%w.]+)", replace(filename))
local f = assert(io.open(filename .. ".chn.xml","wb"))
f:write(s)
f:close()
end
main(...)