-
Notifications
You must be signed in to change notification settings - Fork 15
/
LocaleExtractor.lua
56 lines (45 loc) · 1.31 KB
/
LocaleExtractor.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
44
45
46
47
48
49
50
51
52
53
54
55
56
local strings = { }
local files = { }
function getStrings(filePath)
local content = io.open(filePath, "r"):read("*all")
if filePath:match(".xml$") then
local dir = filePath:match("^(.+\\).-%.xml$")
for fileName in content:gmatch("<%s*Script %s*file%s*=%s*\"(.-%.lua)\"%s*/>") do
getStrings(dir..fileName)
end
for fileName in content:gmatch("<%s*Include %s*file%s*=%s*\"(.-%.xml)\"%s*/>") do
getStrings(dir..fileName)
end
return
end
local file = {
path = filePath,
strings = { },
}
table.insert(files, file)
for str in content:gmatch("L%[\"(.-[^\\])\"%]") do
if not strings[str] then
table.insert(file.strings, "L[\""..str.."\"] = true")
strings[str] = true
end
end
end
function getLocale(file, indexFiles)
local output = { }
for i, filePath in ipairs(indexFiles) do
getStrings(filePath)
end
table.sort(files, function(a, b) return a.path:lower() < b.path:lower() end)
for i, file in ipairs(files) do
table.sort(file.strings, function(a, b) return a:lower() < b:lower() end)
if #file.strings > 0 then
table.insert(output, string.format("--[[ %s ]]--\n%s", file.path, table.concat(file.strings, "\n")))
end
end
local list = io.open(file..".lua", "w")
list:write(table.concat(output, "\n\n"))
end
getLocale("LocaleList", {
"Core\\Core.xml",
"Modules\\Modules.xml",
})