forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllesmereUI_LocaleDev.lua
More file actions
110 lines (103 loc) · 4.37 KB
/
Copy pathEllesmereUI_LocaleDev.lua
File metadata and controls
110 lines (103 loc) · 4.37 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
--------------------------------------------------------------------------------
-- EllesmereUI_LocaleDev.lua
-- In-game translation harvester (/euiloc). Ships with the addon but is fully
-- inert during normal play: it does nothing until a developer runs /euiloc.
--
-- Purpose: capture the complete set of English strings that flow through the
-- localization engine (EllesmereUI.L) so a translator never has to hunt for
-- keys. Because every visible options/unlock/popup string is wrapped in L(),
-- navigating the panels with recording on captures the full key set.
--
-- Workflow:
-- /reload
-- /euiloc on -- start recording (do this BEFORE opening options)
-- ... open every options page, cog popup, and tooltip you want covered ...
-- /euiloc dump deDE -- write a paste-ready L["..."] = "" block to SV
-- /euiloc off -- stop recording
-- The block is written to EllesmereUIDB._localeDump (read it from
-- WTF\Account\<acct>\SavedVariables\EllesmereUI.lua after a /reload or logout).
--------------------------------------------------------------------------------
local EllesmereUI = _G.EllesmereUI
if not EllesmereUI then return end
local recording = false
local origL, origLf = nil, nil
local seen = {} -- set of English keys observed while recording
local function StartRec()
if recording then
EllesmereUI.Print("|cff0cd29fEUILoc|r: already recording.")
return
end
origL = EllesmereUI.L
origLf = EllesmereUI.Lf
EllesmereUI.L = function(s)
if type(s) == "string" and s ~= "" then seen[s] = true end
return origL(s)
end
-- Lf templates (e.g. "Reset %1$s") never reach the wrapped L directly, so
-- record the template string here too.
EllesmereUI.Lf = function(s, ...)
if type(s) == "string" and s ~= "" then seen[s] = true end
return origLf(s, ...)
end
recording = true
EllesmereUI.Print("|cff0cd29fEUILoc|r: recording ON. Open every options page, cog and tooltip, then /euiloc dump <code>.")
end
local function StopRec()
if not recording then return end
if origL then EllesmereUI.L = origL end
if origLf then EllesmereUI.Lf = origLf end
origL, origLf = nil, nil
recording = false
EllesmereUI.Print("|cff0cd29fEUILoc|r: recording OFF.")
end
local function CountSeen()
local n = 0
for _ in pairs(seen) do n = n + 1 end
return n
end
local function Dump(code)
code = code or "xxXX"
local keys = {}
for k in pairs(seen) do keys[#keys + 1] = k end
table.sort(keys)
local lines = {}
lines[#lines + 1] = "-- " .. code .. " key dump from /euiloc (" .. #keys .. " keys). Fill in the right side."
lines[#lines + 1] = 'local L = EllesmereUI.RegisterLocale("' .. code .. '")'
lines[#lines + 1] = "if not L then return end"
lines[#lines + 1] = ""
for _, k in ipairs(keys) do
-- %q produces a safely-escaped Lua string literal for the key.
lines[#lines + 1] = string.format("L[%q] = %q", k, "")
end
local blob = table.concat(lines, "\n")
if not EllesmereUIDB then EllesmereUIDB = {} end
EllesmereUIDB._localeDump = blob
EllesmereUI.Print("|cff0cd29fEUILoc|r: wrote " .. #keys .. " keys to EllesmereUIDB._localeDump (in SavedVariables\\EllesmereUI.lua after /reload or logout).")
end
local function Help()
EllesmereUI.Print("|cff0cd29fEUILoc|r translation harvester:")
EllesmereUI.Print(" /euiloc on - start recording strings")
EllesmereUI.Print(" /euiloc off - stop recording")
EllesmereUI.Print(" /euiloc dump <code> - write seen keys to EllesmereUIDB._localeDump")
EllesmereUI.Print(" /euiloc clear - clear the recorded set")
EllesmereUI.Print(" status: " .. (recording and "recording" or "idle") .. ", " .. CountSeen() .. " keys seen")
end
SLASH_EUILOC1 = "/euiloc"
SlashCmdList["EUILOC"] = function(msg)
-- Trim only; do NOT lowercase -- the locale code arg is case-sensitive (deDE).
msg = (msg or ""):gsub("^%s+", ""):gsub("%s+$", "")
local cmd, arg = msg:match("^(%S+)%s*(.-)$")
cmd = cmd and cmd:lower() or ""
if cmd == "on" then
StartRec()
elseif cmd == "off" then
StopRec()
elseif cmd == "dump" then
Dump(arg ~= "" and arg or nil)
elseif cmd == "clear" then
seen = {}
EllesmereUI.Print("|cff0cd29fEUILoc|r: cleared.")
else
Help()
end
end