-
Notifications
You must be signed in to change notification settings - Fork 0
/
localcheck.lua
88 lines (76 loc) · 2.69 KB
/
localcheck.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
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
local localeName = "Icetip";
local files = {
"Icetip.lua",
"options.lua",
"modules/fade.lua",
"modules/healthbar.lua",
"modules/itemref.lua",
"modules/mousetarget.lua",
"modules/position.lua",
"modules/powerbar.lua",
"modules/raidTarget.lua",
"modules/style.lua",
"modules/aura.lua",
"modules/class.lua"
}
local locale = {}
local baseLocale = "base"
local strings = {}
-- extract data from specified lua files
for idx,filename in pairs(files) do
local file = io.open(string.format("%s%s", filePrefix or "", filename), "r")
assert(file, "Could not open " .. filename)
local text = file:read("*all")
for match in string.gmatch(text, "L%[\"(.-)\"%]") do
strings[match] = true
end
end
local work = {}
for k,v in pairs(strings) do table.insert(work, k) end
table.sort(work)
local AceLocaleHeader = "local L ="
local BabbleFishHeader = "L = {} -- "
local function replaceHeader(content)
return content:gsub(AceLocaleHeader, BabbleFishHeader):gsub("\\", "\\\\"):gsub("\\\"", "\\\\\"")
end
local localizedStrings = {}
table.insert(locale, baseLocale)
-- load existing data from locale files
for idx, lang in ipairs(locale) do
local file = io.open(lang .. ".lua", "r")
assert(file, "Could not open ".. lang .. ".lua for reading")
local content = file:read("*all")
content = replaceHeader(content)
--print(content)
assert(loadstring(content))()
localizedStrings[lang] = L or {}
file:close()
end
-- Write locale files
for idx, lang in ipairs(locale) do
local file = io.open(lang .. ".lua", "w")
assert(file, "Could not open ".. lang .. ".lua for writing")
--file:write("-- Locale是自动生成的, 请不要乱加字符. 否则会出现字符串不存在错误.\n")
if lang == baseLocale then
file:write(string.format("local L = LibStub(\"AceLocale-3.0\"):NewLocale(\"%s\", \"%s\", true)\n", localeName, lang))
file:write("\n")
else
--file:write(string.format("local L = LibStub(\"AceLocale-3.0\"):NewLocale(\"%s\", \"%s\")\n", localeName, lang))
--file:write("if not L then return end\n")
end
file:write("\n")
local L = localizedStrings[lang]
for idx, match in ipairs(work) do
if type(L[match]) == "string" then
file:write(string.format("L[\"%s\"] = \"%s\"\n", match, L[match]))
else
if lang ~= baseLocale then
local value = type(localizedStrings[baseLocale][match]) == "string" and localizedStrings[baseLocale][match] or "true"
file:write(string.format("--L[\"%s\"] = %s\n", match, value))
else
file:write(string.format("L[\"%s\"] = true\n", match))
end
end
end
file:close()
end