comparison gd.lua @ 6:dffc0e7049ad

Initial localization pass.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Fri, 18 Feb 2011 09:53:40 +0000
parents cf777d095730
children baf66f6dd093
comparison
equal deleted inserted replaced
5:cf777d095730 6:dffc0e7049ad
1 1 local nametag = ...
2 local addon = CreateFrame("Frame") --select(2,...) 2 local addon = CreateFrame("Frame")
3 local L = LibStub("AceLocale-3.0"):GetLocale(nametag)
3 local SV 4 local SV
4 5
5 local DEFAULT_CHAT = 2 -- combat log (no constant predefined for that) 6 local DEFAULT_CHAT = 2 -- combat log (no constant predefined for that)
6
7 --if GetLocale() == "enUS" then
8 addon.l10n= {
9 ["LEFT"] = "Players who have left the guild: ",
10 ["JOINED"] = "Players who have joined the guild: ",
11 ["RANK"] = "Players whose rank has changed:",
12 ["LEVEL"] = "Players whose level has changed:",
13 ["NOTES"] = "Players whose notes have changed:",
14
15 ["Oabbrev"] = "O", -- abbreviation for "Officer", specifically the non-public note
16 ["FIELD_rank"] = "Rank",
17 ["FIELD_level"] = "Level",
18 ["FIELD_notes"] = "Player/Officer notes",
19
20 ["NOCHANGE"] = "No changes to tracked fields have been detected.",
21
22 -- Something needs to be done about the walls of description text below.
23 }
24 --elseif .... end
25 7
26 local guild_selection, log_ever_shown 8 local guild_selection, log_ever_shown
27 addon.options = { 9 addon.options = {
28 name = "Guild Delta", 10 --name = filled in during OnInit
29 type = 'group', 11 type = 'group',
30 childGroups = 'tab', 12 childGroups = 'tab',
31 handler = addon, -- functions listed as strings called as addon:func 13 handler = addon, -- functions listed as strings called as addon:func
32 args = { 14 args = {
33 version = { 15 version = {
44 cmdHidden = true, 26 cmdHidden = true,
45 width = 'full', 27 width = 'full',
46 order = 2, 28 order = 2,
47 }, 29 },
48 general = { 30 general = {
49 name = "General", 31 name = GENERAL,
50 desc = "Tracking options", 32 desc = L["Tracking options"],
51 type = 'group', 33 type = 'group',
52 order = 10, 34 order = 10,
53 args = { 35 args = {
54 fields = { 36 fields = {
55 name = "Fields", 37 name = L["Attributes"],
56 desc = "Track changes to these player fields", 38 desc = L["Track changes to these player attributes"],
57 type = 'multiselect', 39 type = 'multiselect',
58 order = 10, 40 order = 10,
59 -- these need to be of function type rather than string keys of members 41 -- these need to be of function type rather than string keys of members
60 values = function(info) return addon:MakeFieldList() end, 42 values = function(info) return addon:MakeFieldList() end,
61 get = function(info,x) return SV.fields[x] end, 43 get = function(info,x) return SV.fields[x] end,
62 set = function(info,x,val) SV.fields[x] = val end, 44 set = function(info,x,val) SV.fields[x] = val end,
63 }, 45 },
64 nochange = { 46 nochange = {
65 name = "No Change", 47 name = L"No Change"],
66 desc = "Print a message even when no changes are detected", 48 desc = L["Print a message even when no changes are detected"],
67 type = 'toggle', 49 type = 'toggle',
68 order = 15, 50 order = 15,
69 get = function() return not not SV.notify_nochange end, 51 get = function() return not not SV.notify_nochange end,
70 set = function(info,val) SV.notify_nochange = val end, 52 set = function(info,val) SV.notify_nochange = val end,
71 }, 53 },
72 color = { 54 color = {
73 name = "Output text color", 55 name = L["Color of output text"],
74 type = 'color', 56 type = 'color',
75 order = 17, 57 order = 17,
76 get = function() return SV.red, SV.green, SV.blue, 1 end, 58 get = function() return SV.red, SV.green, SV.blue, 1 end,
77 set = function(info,...) SV.red, SV.green, SV.blue = ... end, 59 set = function(info,...) SV.red, SV.green, SV.blue = ... end,
78 }, 60 },
82 cmdHidden = true, 64 cmdHidden = true,
83 width = 'full', 65 width = 'full',
84 order = 19, 66 order = 19,
85 }, 67 },
86 guilds = { 68 guilds = {
87 name = "Guilds", 69 name = L["Guilds"],
88 desc = "Guilds for which a roster is known", 70 desc = L["Guilds for which a roster is known"],
89 type = 'select', 71 type = 'select',
90 order = 20, 72 order = 20,
91 width = 'double', 73 width = 'double',
92 values = function(info) return addon:MakeGuildList() end, 74 values = function(info) return addon:MakeGuildList() end,
93 get = function(info) return guild_selection end, 75 get = function(info) return guild_selection end,
94 set = function(info,val) guild_selection = val end, 76 set = function(info,val) guild_selection = val end,
95 }, 77 },
96 clearguild = { 78 clearguild = {
97 name = "Reset Guild", 79 name = L["Reset Guild"],
98 desc = "Erase stored data for selected guild; information will be scanned from scratch on next login.", 80 desc = L"Erase stored data for selected guild; information will be scanned from scratch on next login."],
99 type = 'execute', 81 type = 'execute',
100 order = 22, 82 order = 22,
101 disabled = function() return not guild_selection end, 83 disabled = function() return not guild_selection end,
102 func = function() 84 func = function()
103 assert(type(guild_selection)=='string') 85 assert(type(guild_selection)=='string')
104 local g,r = guild_selection:match("<([^>]+)> %- (.*)") 86 local g,r = guild_selection:match("<([^>]+)> %- (.*)")
105 local m = SV.members[r] 87 local m = SV.members[r]
106 if m then 88 if m then
107 m[g] = nil 89 m[g] = nil
108 else 90 else
109 addon:Print("Hm, error.", r, "can't be matched as a realm name. Please report this as a bug, including the name of the realm and guild.") 91 addon:Printf(L["Error: %s cannot be matched as a realm name. Please report this as a bug, including the name of the realm and guild."], r)
110 end 92 end
111 end, 93 end,
112 }, 94 },
113 }, 95 },
114 }, 96 },
115 output = { 97 output = {
116 name = "Output", 98 name = L["Output"],
117 desc = "What and where to print", 99 desc = L["What and where to print"],
118 type = 'group', 100 type = 'group',
119 order = 20, 101 order = 20,
120 args = { 102 args = {
121 reset = { 103 reset = {
122 name = "Reset Output", 104 name = L["Reset Output"],
123 desc = "Restores default output settings", 105 desc = L["Restores default output settings"],
124 type = 'execute', 106 type = 'execute',
125 order = 10, 107 order = 10,
126 func = "SetChat", 108 func = "SetChat",
127 arg = DEFAULT_CHAT, 109 arg = DEFAULT_CHAT,
128 }, 110 },
132 cmdHidden = true, 114 cmdHidden = true,
133 width = 'full', 115 width = 'full',
134 order = 11, 116 order = 11,
135 }, 117 },
136 print_chatframes = { 118 print_chatframes = {
137 name = "Print Chatframe Numbers", 119 name = L["Print Chatframe Numbers"],
138 desc = "Print each chat window number in its frame, for easy reference in the next slider option", 120 desc = L["Print each chat window number in its frame, for easy reference in the next slider option"],
139 type = 'execute', 121 type = 'execute',
140 --func = print_chatframes filled in below 122 --func = print_chatframes filled in below
141 order = 20, 123 order = 20,
142 }, 124 },
143 chatframe_num = { 125 chatframe_num = {
144 name = "Output Chatframe", 126 name = L["Output Chatframe"],
145 desc = "Which chat window to prefer for printing all the output during login", 127 desc = L["Which chat window to prefer for printing all the output during login"],
146 type = 'range', 128 type = 'range',
147 min = 1, 129 min = 1,
148 max = NUM_CHAT_WINDOWS, 130 max = NUM_CHAT_WINDOWS,
149 step = 1, 131 step = 1,
150 get = function() return tonumber(SV.chatframe) or --[[in case of custom name]]DEFAULT_CHAT end, 132 get = function() return tonumber(SV.chatframe) or --[[in case of custom name]]DEFAULT_CHAT end,
151 set = "SetChat", 133 set = "SetChat",
152 order = 25, 134 order = 25,
153 }, 135 },
154 chatframe_name = { 136 chatframe_name = {
155 name = "Chatframe Override", 137 name = L["Chatframe Override"],
156 desc = "<Advanced> If blank, uses the numerical slider. If set, it is the NAME of a frame with AddMessage capability to use for output.", 138 desc = L["<Advanced> If blank, uses the numerical slider. If set, it is the NAME of a frame with AddMessage capability to use for output."],
157 type = 'input', 139 type = 'input',
158 get = function() 140 get = function()
159 return type(SV.chatframe) == 'string' and SV.chatframe or nil 141 return type(SV.chatframe) == 'string' and SV.chatframe or nil
160 end, 142 end,
161 set = "SetChat", 143 set = "SetChat",
162 order = 26, 144 order = 26,
163 }, 145 },
164 }, 146 },
165 }, 147 },
166 persist = { 148 persist = {
167 name = "Logging", 149 name = L["Logging"],
168 desc = "Storing changes for later review", 150 desc = L["Storing changes for later review"],
169 type = 'group', 151 type = 'group',
170 order = 30, 152 order = 30,
171 args = { 153 args = {
172 note = { 154 note = {
173 --name = filled in locals section 155 --name = filled in locals section
175 cmdHidden = true, 157 cmdHidden = true,
176 width = 'full', 158 width = 'full',
177 order = 10, 159 order = 10,
178 }, 160 },
179 enable = { 161 enable = {
180 name = "Enable Logging", 162 name = L["Enable Logging"],
181 desc = [[Accumulate all deltas, including a timestamp. |cffFF0000WARNING|r: if logging was enabled and you turn it off, the log itself will not be saved when exiting the game.]], 163 desc = L["Accumulate all deltas, including a timestamp. |cffFF0000WARNING|r: if logging was enabled and you turn it off, the log itself will not be saved when exiting the game."],
182 type = 'toggle', 164 type = 'toggle',
183 order = 15, 165 order = 15,
184 get = function() return SV.logging end, 166 get = function() return SV.logging end,
185 set = function(i,v) 167 set = function(i,v)
186 SV.logging = v 168 SV.logging = v
187 log_ever_shown = SV.logging or log_ever_shown 169 log_ever_shown = SV.logging or log_ever_shown
188 end, 170 end,
189 }, 171 },
190 clearlog = { 172 clearlog = {
191 name = "Reset Log", 173 name = L["Reset Log"],
192 desc = "Erase accumulated deltas.", 174 desc = L["Erase accumulated deltas"],
193 type = 'execute', 175 type = 'execute',
194 order = 20, 176 order = 20,
195 hidden = function() return not (SV.logging or log_ever_shown) end, 177 hidden = function() return not (SV.logging or log_ever_shown) end,
196 disabled = function() return not SV.logging end, 178 disabled = function() return not SV.logging end,
197 func = function() 179 func = function()
198 SV.logtext = nil 180 SV.logtext = nil
199 end, 181 end,
200 }, 182 },
201 log = { 183 log = {
202 name = "Log", 184 name = L["Log"],
203 desc = "If you make changes, don't forget to click 'Accept' to save them. Scroll down if needed.", 185 desc = L["If you make changes, don't forget to click 'Accept' to save them. Scroll down if needed."],
204 type = 'input', 186 type = 'input',
205 order = 25, 187 order = 25,
206 multiline = 15, 188 multiline = 15,
207 width = 'full', 189 width = 'full',
208 hidden = function() return not (SV.logging or log_ever_shown) end, 190 hidden = function() return not (SV.logging or log_ever_shown) end,
253 235
254 function addon.options.args.output.args.print_chatframes.func() 236 function addon.options.args.output.args.print_chatframes.func()
255 for i = 1, NUM_CHAT_WINDOWS do 237 for i = 1, NUM_CHAT_WINDOWS do
256 local cf = _G['ChatFrame'..i] 238 local cf = _G['ChatFrame'..i]
257 if not cf then break end 239 if not cf then break end
258 addon:Print(cf, "This is frame number", i) 240 addon:Printf(cf, L["This is frame number %d."], i)
259 end 241 end
260 end 242 end
261 243
244 -- Localize these?
262 addon.options.args.note.name = 245 addon.options.args.note.name =
263 "You can use the '/guilddelta' command to open the options window.\n\n".. 246 "You can use the '/guilddelta' command to open the options window.\n\n"..
264 "The guild roster has already been scanned by the time you see this. Therefore, ".. 247 "The guild roster has already been scanned by the time you see this. Therefore, "..
265 "if you make any changes to the Fields section below, you should probably relog ".. 248 "if you make any changes to the Fields section below, you should probably relog "..
266 "immediately to begin tracking the changed fields. Changes to the contents *OF* ".. 249 "immediately to begin tracking the changed fields. Changes to the contents *OF* "..
275 "any changes to the text, the changes will be preserved. (You can remove uninteresting ".. 258 "any changes to the text, the changes will be preserved. (You can remove uninteresting "..
276 "changes, add reminders to yourself, and so forth.)\n\n" 259 "changes, add reminders to yourself, and so forth.)\n\n"
277 260
278 261
279 ----------------------------------------------------------------------------- 262 -----------------------------------------------------------------------------
280 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "GuildDelta", 263 addon = LibStub("AceAddon-3.0"):NewAddon(addon, nametag,
281 "AceConsole-3.0") 264 "AceConsole-3.0")
282 265
283 function addon:OnInitialize() 266 function addon:OnInitialize()
284 if _G.GuildDeltaSV == nil then 267 if _G.GuildDeltaSV == nil then
285 -- Defaults need to transition from potential older savedvars 268 -- Defaults need to transition from potential older savedvars
311 self.FinishLog = nil 294 self.FinishLog = nil
312 end 295 end
313 -- Remove everything. 296 -- Remove everything.
314 function addon:unload() 297 function addon:unload()
315 self:cleanup() 298 self:cleanup()
316 LibStub("AceAddon-3.0").addons["GuildDelta"] = nil 299 LibStub("AceAddon-3.0").addons[nametag] = nil
317 addon = nil; 300 addon = nil;
318 -- put the userdata back so it counts as a Frame object again 301 -- put the userdata back so it counts as a Frame object again
319 local ud = self[0] 302 local ud = self[0]
320 table.wipe(self) 303 table.wipe(self)
321 self[0] = ud 304 self[0] = ud
329 312
330 self:RegisterEvent("GUILD_ROSTER_UPDATE") 313 self:RegisterEvent("GUILD_ROSTER_UPDATE")
331 self:SetScript("OnEvent", self.GuildUpdate) 314 self:SetScript("OnEvent", self.GuildUpdate)
332 315
333 self.options.args.version.name = 316 self.options.args.version.name =
334 "|cff30adffVersion " .. (GetAddOnMetadata("GuildDelta", "Version") or "?") .. "|r" 317 "|cff30adffVersion " .. (GetAddOnMetadata(nametag, "Version") or "?") .. "|r"
335 LibStub("AceConfig-3.0"):RegisterOptionsTable("GuildDelta", self.options) 318 LibStub("AceConfig-3.0"):RegisterOptionsTable(nametag, self.options)
336 --[[self.optionsFrame =]] LibStub("AceConfigDialog-3.0"):AddToBlizOptions("GuildDelta", "Guild Delta") 319 --[[self.optionsFrame =]] LibStub("AceConfigDialog-3.0"):AddToBlizOptions(nametag, "Guild Delta")
337 self:RegisterChatCommand("guilddelta", "OnChatCommand") 320 self:RegisterChatCommand("guilddelta", "OnChatCommand")
338 self:SetChat(self) 321 self:SetChat(self)
339 log_ever_shown = SV.logging 322 log_ever_shown = SV.logging
340 self.OnEnable = nil 323 self.OnEnable = nil
341 end 324 end
342 325
343 326
344 function addon:OnChatCommand (input) 327 function addon:OnChatCommand (input)
345 if not input or input:trim() == "" then 328 if not input or input:trim() == "" then
346 LibStub("AceConfigDialog-3.0"):Open("GuildDelta") 329 LibStub("AceConfigDialog-3.0"):Open(nametag)
347 else 330 else
348 LibStub("AceConfigCmd-3.0").HandleCommand(self, "guilddelta", "GuildDelta", input) 331 LibStub("AceConfigCmd-3.0").HandleCommand(self, "guilddelta", nametag, input)
349 end 332 end
350 end 333 end
351 334
352 335
353 -- 1 arg: (self) called during startup to initialize 336 -- 1 arg: (self) called during startup to initialize
381 nframe = _G[n] -- advanced name 364 nframe = _G[n] -- advanced name
382 end 365 end
383 if type(nframe) == 'table' and type(nframe.AddMessage) == 'function' then 366 if type(nframe) == 'table' and type(nframe.AddMessage) == 'function' then
384 if not isauto then 367 if not isauto then
385 SV.chatframe = n 368 SV.chatframe = n
386 self:Print("Now printing to chat frame", n, 369 self:Print(L["Now printing to chat frame"], n,
387 (type(nframe.name)=='string' and ("(".. nframe.name .. ")") or "")) 370 (type(nframe.name)=='string' and ("(".. nframe.name .. ")") or ""))
388 end 371 end
389 chatframe = nframe 372 chatframe = nframe
390 else 373 else
391 self:Printf("EEEEEEEK! '%s' was not a valid chat frame number/name, no change has been made.", n) 374 self:Printf(L["'%s' was not a valid chat frame number/name, no change has been made."], n)
392 end 375 end
393 end 376 end
394 377
395 378
396 -- Not a "normal" PLAYER_LOGOUT handler; this only fires if the player is in 379 -- Not a "normal" PLAYER_LOGOUT handler; this only fires if the player is in
412 self:SetScript("OnEvent", self.PLAYER_LOGOUT) -- keepin' it real^H^H^H^Hsmall and kludgey 395 self:SetScript("OnEvent", self.PLAYER_LOGOUT) -- keepin' it real^H^H^H^Hsmall and kludgey
413 self:RegisterEvent("PLAYER_LOGOUT") 396 self:RegisterEvent("PLAYER_LOGOUT")
414 self.GuildUpdate = nil 397 self.GuildUpdate = nil
415 398
416 if SV.logtext and #SV.logtext > 20000 then 399 if SV.logtext and #SV.logtext > 20000 then
417 self:Print("Your accumulated logfile has grown rather large; you should consider copying it out and clearing it.") 400 self:Print(L["Your accumulated logfile has grown rather large; you should consider copying it out and clearing it."])
418 end 401 end
419 402
420 local guild = assert((GetGuildInfo("player")), "GetGuildInfo returns nil?") 403 local guild = assert((GetGuildInfo("player")), "GetGuildInfo returns nil?")
421 local realm = assert(GetRealmName(), "GetRealmName returns nil?") 404 local realm = assert(GetRealmName(), "GetRealmName returns nil?")
422 local members = SV.members 405 local members = SV.members
423 local l10n = self.l10n
424 if members[realm] 406 if members[realm]
425 and members[realm][guild] 407 and members[realm][guild]
426 and #(members[realm][guild]) > 0 408 and #(members[realm][guild]) > 0
427 then 409 then
428 -- moved the normal case below 410 -- moved the normal case below
429 else 411 else
430 -- new user, or new guild, or any number of things 412 -- new user, or new guild, or any number of things
431 self:Print("GuildDelta initializing roster...") 413 self:Print(L["GuildDelta initializing roster..."])
432 members[realm] = members[realm] or {} 414 members[realm] = members[realm] or {}
433 members[realm][guild] = self:current_guild_info(current_n) 415 members[realm][guild] = self:current_guild_info(current_n)
434 return self:cleanup() 416 return self:cleanup()
435 end 417 end
436 418
437 -- table.insert with notes if available 419 -- table.insert with notes if available
438 -- concatentation of string-only args faster than string.format of same 420 -- concatentation of string-only args faster than string.format of same
439 local function tins (t, x) 421 local function tins (t, x)
440 local s = x.name 422 local s = x.name
441 if x.onote and (x.onote ~= "") then 423 if x.onote and (x.onote ~= "") then
442 s = s .. "(" .. l10n.Oabbrev .. ": " .. x.onote .. ")" 424 s = s .. "(" .. L["Oabbrev"] .. ": " .. x.onote .. ")"
443 end 425 end
444 if x.pnote and (x.pnote ~= "") then 426 if x.pnote and (x.pnote ~= "") then
445 s = s .. "(" .. x.pnote .. ")" 427 s = s .. "(" .. x.pnote .. ")"
446 end 428 end
447 tinsert(t, s) 429 tinsert(t, s)
471 end 453 end
472 if C.pnote and (P.pnote ~= C.pnote) then 454 if C.pnote and (P.pnote ~= C.pnote) then
473 tinsert(notes, {C.name, C.pnote}) 455 tinsert(notes, {C.name, C.pnote})
474 end 456 end
475 if C.onote and (P.onote ~= C.onote) then 457 if C.onote and (P.onote ~= C.onote) then
476 tinsert(notes, {C.name, "["..l10n.Oabbrev.."]: "..C.onote}) 458 tinsert(notes, {C.name, "["..L["Oabbrev"].."]: "..C.onote})
477 end 459 end
478 460
479 elseif P.name < C.name then 461 elseif P.name < C.name then
480 -- entry at index p not at c -> somebody has left 462 -- entry at index p not at c -> somebody has left
481 tins (left, P) 463 tins (left, P)
499 -- show results 481 -- show results
500 if SV.logging then self.logquay = {} end 482 if SV.logging then self.logquay = {} end
501 local m, changes 483 local m, changes
502 if #left > 0 then 484 if #left > 0 then
503 changes = true 485 changes = true
504 m = l10n.LEFT .. table.concat(left, ", ") 486 m = L["LEFT"] .. table.concat(left, ", ")
505 cprt(m) 487 cprt(m)
506 end 488 end
507 489
508 if #joined > 0 then 490 if #joined > 0 then
509 changes = true 491 changes = true
510 m = l10n.JOINED .. table.concat(joined, ", ") 492 m = L["JOINED"] .. table.concat(joined, ", ")
511 cprt(m) 493 cprt(m)
512 end 494 end
513 495
514 if #rank > 0 then 496 if #rank > 0 then
515 changes = true 497 changes = true
516 cprt(l10n.RANK) 498 cprt(L["RANK"])
517 for i = 1, #rank do 499 for i = 1, #rank do
518 cprt(rank[i][1]..': '..rank[i][2]) 500 cprt(rank[i][1]..': '..rank[i][2])
519 end 501 end
520 end 502 end
521 503
522 if #level > 0 then 504 if #level > 0 then
523 changes = true 505 changes = true
524 cprt(l10n.LEVEL) 506 cprt(L["LEVEL"])
525 for i = 1, #level do 507 for i = 1, #level do
526 cprt(level[i][1]..': '..level[i][2]) 508 cprt(level[i][1]..': '..level[i][2])
527 end 509 end
528 end 510 end
529 511
530 if #notes > 0 then 512 if #notes > 0 then
531 changes = true 513 changes = true
532 cprt(l10n.NOTES) 514 cprt(L["NOTES"])
533 for i = 1, #notes do 515 for i = 1, #notes do
534 cprt(notes[i][1]..': "'..notes[i][2]..'"') 516 cprt(notes[i][1]..': "'..notes[i][2]..'"')
535 end 517 end
536 end 518 end
537 519
538 if SV.logging then self:FinishLog(guild,realm) end 520 if SV.logging then self:FinishLog(guild,realm) end
539 if SV.notify_nochange and (not changes) then cprt(l10n.NOCHANGE) end 521 if SV.notify_nochange and (not changes) then cprt(L["NOCHANGE"]) end
540 members[realm][guild] = current 522 members[realm][guild] = current
541 self:cleanup() 523 self:cleanup()
542 end 524 end
543 525
544 526
545 function addon:MakeFieldList() 527 function addon:MakeFieldList()
546 if not fieldlist then 528 if not fieldlist then
547 fieldlist = {} 529 fieldlist = {}
548 for name in pairs(SV.fields) do 530 for name in pairs(SV.fields) do
549 fieldlist[name] = self.l10n["FIELD_"..name] 531 fieldlist[name] = L["FIELD_"..name]
550 end 532 end
551 end 533 end
552 return fieldlist 534 return fieldlist
553 end 535 end
554 536