forked from LiangYuxuan/SavedInstances
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babelfish.lua
58 lines (48 loc) · 1.57 KB
/
babelfish.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
57
58
#!/usr/bin/lua
-- Prefix to all files if this script is run from a subdir, for example
local filePrefix = ""
-- luacheck: globals io
local function generateFileList(dir)
local fileTable = {}
local p = io.popen('find "'.. dir ..'" -name "*.lua" -not -path "*/Locales/*" -not -path "*/Libs/*"')
for file in p:lines() do
table.insert(fileTable, file)
end
return fileTable
end
local fileList = {
SavedInstances_Main = generateFileList("SavedInstances"),
}
local ordered = {
"SavedInstances_Main",
}
local function parseFile(filename)
local strings = {}
local file = assert(io.open(string.format("%s%s", filePrefix or "", filename), "r"), "Could not open " .. filename)
local text = file:read("*all")
file:close()
for match in string.gmatch(text, "L%[\"(.-)\"%]") do
strings[match] = true
end
return strings
end
-- extract data from specified lua files
for _, namespace in ipairs(ordered) do
print(namespace)
local ns_file = assert(io.open(namespace .. ".lua", "w"), "Error opening file")
for _, file in ipairs(fileList[namespace]) do
local strings = parseFile(file)
local sorted = {}
for k in next, strings do
table.insert(sorted, k)
end
table.sort(sorted)
if #sorted > 0 then
for _, v in ipairs(sorted) do
ns_file:write(string.format("L[\"%s\"] = true\n", v))
end
end
print(" (" .. #sorted .. ") " .. file)
end
ns_file:close()
end