Mercurial > wow > reaction
comparison lib/AceLocale-2.2/AceLocale-2.2.lua @ 22:1b9323256a1b
Merging in 1.0 dev tree
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 07 Mar 2008 22:10:55 +0000 |
parents | libs/AceLocale-2.2/AceLocale-2.2.lua@f920db5fc6b1 |
children |
comparison
equal
deleted
inserted
replaced
21:90bf38d48efd | 22:1b9323256a1b |
---|---|
1 --[[ | |
2 Name: AceLocale-2.2 | |
3 Revision: $Rev: 40629 $ | |
4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team) | |
5 Inspired By: Ace 1.x by Turan (turan@gryphon.com) | |
6 Website: http://www.wowace.com/ | |
7 Documentation: http://www.wowace.com/index.php/AceLocale-2.2 | |
8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceLocale-2.2 | |
9 Description: Localization library for addons to use to handle proper | |
10 localization and internationalization. | |
11 Dependencies: AceLibrary | |
12 License: LGPL v2.1 | |
13 ]] | |
14 | |
15 local MAJOR_VERSION = "AceLocale-2.2" | |
16 local MINOR_VERSION = "$Revision: 40629 $" | |
17 | |
18 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end | |
19 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end | |
20 | |
21 local AceLocale = {} | |
22 AceLocale.prototype = { class = AceLocale } | |
23 | |
24 local BASE_TRANSLATIONS, DEBUGGING, TRANSLATIONS, BASE_LOCALE, TRANSLATION_TABLES, REVERSE_TRANSLATIONS, STRICTNESS, DYNAMIC_LOCALES, CURRENT_LOCALE, NAME | |
25 | |
26 local _G = _G | |
27 local rawget = rawget | |
28 local rawset = rawset | |
29 local type = type | |
30 local pairs = pairs | |
31 local next = next | |
32 local getmetatable = getmetatable | |
33 local setmetatable = setmetatable | |
34 local GetTime = GetTime | |
35 local geterrorhandler = geterrorhandler | |
36 local pcall = pcall | |
37 local ipairs = ipairs | |
38 local GetLocale = GetLocale | |
39 | |
40 local newRegistries = {} | |
41 local scheduleClear | |
42 | |
43 local lastSelf | |
44 local strict__index = function(self, key) | |
45 lastSelf = self | |
46 local value = (rawget(self, TRANSLATIONS) or AceLocale.prototype)[key] | |
47 rawset(self, key, value) | |
48 return value | |
49 end | |
50 local nonstrict__index = function(self, key) | |
51 lastSelf = self | |
52 local t = rawget(self, TRANSLATIONS) | |
53 if t then | |
54 local value = rawget(t, key) | |
55 if value then | |
56 rawset(self, key, value) | |
57 return value | |
58 end | |
59 end | |
60 local value = (rawget(self, BASE_TRANSLATIONS) or AceLocale.prototype)[key] | |
61 rawset(self, key, value) | |
62 return value | |
63 end | |
64 | |
65 local __newindex = function(self, k, v) | |
66 if type(v) ~= "function" and type(k) ~= "table" then | |
67 AceLocale.error(self, "Cannot change the values of an AceLocale instance.") | |
68 end | |
69 rawset(self, k, v) | |
70 end | |
71 | |
72 local __tostring = function(self) | |
73 if type(rawget(self, 'GetLibraryVersion')) == "function" then | |
74 return self:GetLibraryVersion() | |
75 else | |
76 return "AceLocale(" .. self[NAME] .. ")" | |
77 end | |
78 end | |
79 | |
80 local function clearCache(self) | |
81 for k, v in pairs(AceLocale.prototype) do | |
82 if type(v) == "function" and type(rawget(self, k)) == "function" then | |
83 self[k] = nil | |
84 end | |
85 end | |
86 if not rawget(self, BASE_TRANSLATIONS) then | |
87 return | |
88 end | |
89 | |
90 local cache = self[BASE_TRANSLATIONS] | |
91 rawset(self, REVERSE_TRANSLATIONS, nil) | |
92 | |
93 for k in pairs(self) do | |
94 if rawget(cache, k) ~= nil then | |
95 self[k] = nil | |
96 end | |
97 end | |
98 rawset(self, 'tmp', true) | |
99 self.tmp = nil | |
100 end | |
101 | |
102 local strict_instance_mt, nonstrict_instance_mt | |
103 local baseTranslations_mt | |
104 | |
105 local function refixInstance(instance) | |
106 if getmetatable(instance) then | |
107 setmetatable(instance, nil) | |
108 end | |
109 local translations = instance[TRANSLATIONS] | |
110 if translations then | |
111 if getmetatable(translations) then | |
112 setmetatable(translations, nil) | |
113 end | |
114 local baseTranslations = instance[BASE_TRANSLATIONS] | |
115 if getmetatable(baseTranslations) then | |
116 setmetatable(baseTranslations, nil) | |
117 end | |
118 if translations == baseTranslations or instance[STRICTNESS] then | |
119 setmetatable(instance, strict_instance_mt) | |
120 | |
121 setmetatable(translations, baseTranslations_mt) | |
122 else | |
123 setmetatable(instance, nonstrict_instance_mt) | |
124 | |
125 setmetatable(baseTranslations, baseTranslations_mt) | |
126 end | |
127 else | |
128 setmetatable(instance, strict_instance_mt) | |
129 end | |
130 clearCache(instance) | |
131 newRegistries[instance] = true | |
132 scheduleClear() | |
133 return instance | |
134 end | |
135 | |
136 function AceLocale:new(name) | |
137 self:argCheck(name, 2, "string") | |
138 | |
139 if self.registry[name] and type(rawget(self.registry[name], 'GetLibraryVersion')) ~= "function" then | |
140 return self.registry[name] | |
141 end | |
142 | |
143 AceLocale.registry[name] = refixInstance({ | |
144 [STRICTNESS] = false, | |
145 [NAME] = name, | |
146 }) | |
147 newRegistries[AceLocale.registry[name]] = true | |
148 return AceLocale.registry[name] | |
149 end | |
150 | |
151 function AceLocale.prototype:EnableDebugging() | |
152 if rawget(self, BASE_TRANSLATIONS) then | |
153 AceLocale.error(self, "Cannot enable debugging after a translation has been registered.") | |
154 end | |
155 rawset(self, DEBUGGING, true) | |
156 end | |
157 | |
158 function AceLocale.prototype:EnableDynamicLocales(override) | |
159 AceLocale.argCheck(self, override, 2, "boolean", "nil") | |
160 if not override and rawget(self, BASE_TRANSLATIONS) then | |
161 AceLocale.error(self, "Cannot enable dynamic locales after a translation has been registered.") | |
162 end | |
163 if not rawget(self, DYNAMIC_LOCALES) then | |
164 rawset(self, DYNAMIC_LOCALES, true) | |
165 if rawget(self, BASE_LOCALE) then | |
166 if not rawget(self, TRANSLATION_TABLES) then | |
167 rawset(self, TRANSLATION_TABLES, {}) | |
168 end | |
169 self[TRANSLATION_TABLES][self[BASE_LOCALE]] = self[BASE_TRANSLATIONS] | |
170 self[TRANSLATION_TABLES][self[CURRENT_LOCALE]] = self[TRANSLATIONS] | |
171 end | |
172 end | |
173 end | |
174 | |
175 function AceLocale.prototype:RegisterTranslations(locale, func) | |
176 AceLocale.argCheck(self, locale, 2, "string") | |
177 AceLocale.argCheck(self, func, 3, "function") | |
178 | |
179 if locale == rawget(self, BASE_LOCALE) then | |
180 AceLocale.error(self, "Cannot provide the same locale more than once. %q provided twice.", locale) | |
181 end | |
182 | |
183 if rawget(self, BASE_TRANSLATIONS) and GetLocale() ~= locale then | |
184 if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then | |
185 if not rawget(self, TRANSLATION_TABLES) then | |
186 rawset(self, TRANSLATION_TABLES, {}) | |
187 end | |
188 if self[TRANSLATION_TABLES][locale] then | |
189 AceLocale.error(self, "Cannot provide the same locale more than once. %q provided twice.", locale) | |
190 end | |
191 local t = func() | |
192 func = nil | |
193 if type(t) ~= "table" then | |
194 AceLocale.error(self, "Bad argument #3 to `RegisterTranslations'. function did not return a table. (expected table, got %s)", type(t)) | |
195 end | |
196 self[TRANSLATION_TABLES][locale] = t | |
197 t = nil | |
198 end | |
199 func = nil | |
200 return | |
201 end | |
202 local t = func() | |
203 func = nil | |
204 if type(t) ~= "table" then | |
205 AceLocale.error(self, "Bad argument #3 to `RegisterTranslations'. function did not return a table. (expected table, got %s)", type(t)) | |
206 end | |
207 | |
208 rawset(self, TRANSLATIONS, t) | |
209 if not rawget(self, BASE_TRANSLATIONS) then | |
210 rawset(self, BASE_TRANSLATIONS, t) | |
211 rawset(self, BASE_LOCALE, locale) | |
212 for key,value in pairs(t) do | |
213 if value == true then | |
214 t[key] = key | |
215 end | |
216 end | |
217 else | |
218 for key, value in pairs(self[TRANSLATIONS]) do | |
219 if not rawget(self[BASE_TRANSLATIONS], key) then | |
220 AceLocale.error(self, "Improper translation exists. %q is likely misspelled for locale %s.", key, locale) | |
221 end | |
222 if value == true then | |
223 AceLocale.error(self, "Can only accept true as a value on the base locale. %q is the base locale, %q is not.", rawget(self, BASE_LOCALE), locale) | |
224 end | |
225 end | |
226 end | |
227 rawset(self, CURRENT_LOCALE, locale) | |
228 if not rawget(self, 'reverse') then | |
229 rawset(self, 'reverse', setmetatable({}, { __index = function(self2, key) | |
230 local self = AceLocale.reverseToBase[self2] | |
231 if not rawget(self, REVERSE_TRANSLATIONS) then | |
232 self:GetReverseTranslation(key) | |
233 end | |
234 self.reverse = self[REVERSE_TRANSLATIONS] | |
235 return self.reverse[key] | |
236 end })) | |
237 AceLocale.reverseToBase[self.reverse] = self | |
238 end | |
239 refixInstance(self) | |
240 if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then | |
241 if not rawget(self, TRANSLATION_TABLES) then | |
242 rawset(self, TRANSLATION_TABLES, {}) | |
243 end | |
244 self[TRANSLATION_TABLES][locale] = t | |
245 end | |
246 t = nil | |
247 end | |
248 | |
249 function AceLocale.prototype:SetLocale(locale) | |
250 AceLocale.argCheck(self, locale, 2, "string", "boolean") | |
251 if not rawget(self, DYNAMIC_LOCALES) then | |
252 AceLocale.error(self, "Cannot call `SetLocale' without first calling `EnableDynamicLocales'.") | |
253 end | |
254 if not rawget(self, TRANSLATION_TABLES) then | |
255 AceLocale.error(self, "Cannot call `SetLocale' without first calling `RegisterTranslations'.") | |
256 end | |
257 if locale == true then | |
258 locale = GetLocale() | |
259 if not self[TRANSLATION_TABLES][locale] then | |
260 locale = self[BASE_LOCALE] | |
261 end | |
262 end | |
263 | |
264 if self[CURRENT_LOCALE] == locale then | |
265 return | |
266 end | |
267 | |
268 if not self[TRANSLATION_TABLES][locale] then | |
269 AceLocale.error(self, "Locale %q not registered.", locale) | |
270 end | |
271 | |
272 self[TRANSLATIONS] = self[TRANSLATION_TABLES][locale] | |
273 self[CURRENT_LOCALE] = locale | |
274 refixInstance(self) | |
275 end | |
276 | |
277 function AceLocale.prototype:GetLocale() | |
278 if not rawget(self, TRANSLATION_TABLES) then | |
279 AceLocale.error(self, "Cannot call `GetLocale' without first calling `RegisterTranslations'.") | |
280 end | |
281 return self[CURRENT_LOCALE] | |
282 end | |
283 | |
284 local function iter(t, position) | |
285 return (next(t, position)) | |
286 end | |
287 | |
288 function AceLocale.prototype:IterateAvailableLocales() | |
289 if not rawget(self, DYNAMIC_LOCALES) then | |
290 AceLocale.error(self, "Cannot call `IterateAvailableLocales' without first calling `EnableDynamicLocales'.") | |
291 end | |
292 if not rawget(self, TRANSLATION_TABLES) then | |
293 AceLocale.error(self, "Cannot call `IterateAvailableLocales' without first calling `RegisterTranslations'.") | |
294 end | |
295 return iter, self[TRANSLATION_TABLES], nil | |
296 end | |
297 | |
298 function AceLocale.prototype:HasLocale(locale) | |
299 if not rawget(self, DYNAMIC_LOCALES) then | |
300 AceLocale.error(self, "Cannot call `HasLocale' without first calling `EnableDynamicLocales'.") | |
301 end | |
302 AceLocale.argCheck(self, locale, 2, "string") | |
303 return rawget(self, TRANSLATION_TABLES) and self[TRANSLATION_TABLES][locale] ~= nil | |
304 end | |
305 | |
306 function AceLocale.prototype:SetStrictness(strict) | |
307 AceLocale.argCheck(self, strict, 2, "boolean") | |
308 local mt = getmetatable(self) | |
309 if not mt then | |
310 AceLocale.error(self, "Cannot call `SetStrictness' without a metatable.") | |
311 end | |
312 if not rawget(self, TRANSLATIONS) then | |
313 AceLocale.error(self, "No translations registered.") | |
314 end | |
315 rawset(self, STRICTNESS, strict) | |
316 refixInstance(self) | |
317 end | |
318 | |
319 local function initReverse(self) | |
320 rawset(self, REVERSE_TRANSLATIONS, setmetatable({}, { __index = function(_, key) | |
321 AceLocale.error(self, "Reverse translation for %q does not exist", key) | |
322 end })) | |
323 local alpha = self[TRANSLATIONS] | |
324 local bravo = self[REVERSE_TRANSLATIONS] | |
325 for base, localized in pairs(alpha) do | |
326 bravo[localized] = base | |
327 end | |
328 end | |
329 | |
330 function AceLocale.prototype:GetTranslation(text) | |
331 AceLocale.argCheck(self, text, 1, "string", "number") | |
332 if not rawget(self, TRANSLATIONS) then | |
333 AceLocale.error(self, "No translations registered") | |
334 end | |
335 return self[text] | |
336 end | |
337 | |
338 function AceLocale.prototype:GetStrictTranslation(text) | |
339 AceLocale.argCheck(self, text, 1, "string", "number") | |
340 local x = rawget(self, TRANSLATIONS) | |
341 if not x then | |
342 AceLocale.error(self, "No translations registered") | |
343 end | |
344 local value = rawget(x, text) | |
345 if value == nil then | |
346 local _, ret = pcall(AceLocale.error, self, "Translation %q does not exist for locale %s", text, self[CURRENT_LOCALE]) | |
347 geterrorhandler()(ret) | |
348 return text | |
349 end | |
350 return value | |
351 end | |
352 | |
353 function AceLocale.prototype:GetReverseTranslation(text) | |
354 local x = rawget(self, REVERSE_TRANSLATIONS) | |
355 if not x then | |
356 if not rawget(self, TRANSLATIONS) then | |
357 AceLocale.error(self, "No translations registered") | |
358 end | |
359 initReverse(self) | |
360 x = self[REVERSE_TRANSLATIONS] | |
361 end | |
362 local translation = x[text] | |
363 if not translation then | |
364 local _, ret = pcall(AceLocale.error, self, "Reverse translation for %q does not exist", text) | |
365 geterrorhandler()(ret) | |
366 return text | |
367 end | |
368 return translation | |
369 end | |
370 | |
371 function AceLocale.prototype:GetIterator() | |
372 local x = rawget(self, TRANSLATIONS) | |
373 if not x then | |
374 AceLocale.error(self, "No translations registered") | |
375 end | |
376 return next, x, nil | |
377 end | |
378 | |
379 function AceLocale.prototype:GetReverseIterator() | |
380 local x = rawget(self, REVERSE_TRANSLATIONS) | |
381 if not x then | |
382 if not rawget(self, TRANSLATIONS) then | |
383 AceLocale.error(self, "No translations registered") | |
384 end | |
385 initReverse(self) | |
386 x = self[REVERSE_TRANSLATIONS] | |
387 end | |
388 return next, x, nil | |
389 end | |
390 | |
391 function AceLocale.prototype:HasTranslation(text) | |
392 AceLocale.argCheck(self, text, 1, "string", "number") | |
393 local x = rawget(self, TRANSLATIONS) | |
394 if not x then | |
395 AceLocale.error(self, "No translations registered") | |
396 end | |
397 return rawget(x, text) and true | |
398 end | |
399 | |
400 function AceLocale.prototype:HasBaseTranslation(text) | |
401 AceLocale.argCheck(self, text, 1, "string", "number") | |
402 local x = rawget(self, BASE_TRANSLATIONS) | |
403 if not x then | |
404 AceLocale.error(self, "No translations registered") | |
405 end | |
406 return rawget(x, text) and true | |
407 end | |
408 | |
409 function AceLocale.prototype:HasReverseTranslation(text) | |
410 local x = rawget(self, REVERSE_TRANSLATIONS) | |
411 if not x then | |
412 if not rawget(self, TRANSLATIONS) then | |
413 AceLocale.error(self, "No translations registered") | |
414 end | |
415 initReverse(self) | |
416 x = self[REVERSE_TRANSLATIONS] | |
417 end | |
418 return rawget(x, text) and true | |
419 end | |
420 | |
421 function AceLocale.prototype:Debug() | |
422 if not rawget(self, DEBUGGING) then | |
423 return | |
424 end | |
425 local words = {} | |
426 local locales = {"enUS", "deDE", "frFR", "koKR", "zhCN", "zhTW", "esES"} | |
427 local localizations = {} | |
428 DEFAULT_CHAT_FRAME:AddMessage("--- AceLocale Debug ---") | |
429 for _,locale in ipairs(locales) do | |
430 if not self[TRANSLATION_TABLES][locale] then | |
431 DEFAULT_CHAT_FRAME:AddMessage(("Locale %q not found"):format(locale)) | |
432 else | |
433 localizations[locale] = self[TRANSLATION_TABLES][locale] | |
434 end | |
435 end | |
436 local localeDebug = {} | |
437 for locale, localization in pairs(localizations) do | |
438 localeDebug[locale] = {} | |
439 for word in pairs(localization) do | |
440 if type(localization[word]) == "table" then | |
441 if type(words[word]) ~= "table" then | |
442 words[word] = {} | |
443 end | |
444 for bit in pairs(localization[word]) do | |
445 if type(localization[word][bit]) == "string" then | |
446 words[word][bit] = true | |
447 end | |
448 end | |
449 elseif type(localization[word]) == "string" then | |
450 words[word] = true | |
451 end | |
452 end | |
453 end | |
454 for word in pairs(words) do | |
455 if type(words[word]) == "table" then | |
456 for bit in pairs(words[word]) do | |
457 for locale, localization in pairs(localizations) do | |
458 if not rawget(localization, word) or not localization[word][bit] then | |
459 localeDebug[locale][word .. "::" .. bit] = true | |
460 end | |
461 end | |
462 end | |
463 else | |
464 for locale, localization in pairs(localizations) do | |
465 if not rawget(localization, word) then | |
466 localeDebug[locale][word] = true | |
467 end | |
468 end | |
469 end | |
470 end | |
471 for locale, t in pairs(localeDebug) do | |
472 if not next(t) then | |
473 DEFAULT_CHAT_FRAME:AddMessage(("Locale %q complete"):format(locale)) | |
474 else | |
475 DEFAULT_CHAT_FRAME:AddMessage(("Locale %q missing:"):format(locale)) | |
476 for word in pairs(t) do | |
477 DEFAULT_CHAT_FRAME:AddMessage((" %q"):format(word)) | |
478 end | |
479 end | |
480 end | |
481 DEFAULT_CHAT_FRAME:AddMessage("--- End AceLocale Debug ---") | |
482 end | |
483 | |
484 setmetatable(AceLocale.prototype, { | |
485 __index = function(self, k) | |
486 if type(k) ~= "table" and k ~= 0 and k ~= "GetLibraryVersion" and k ~= "error" and k ~= "assert" and k ~= "argCheck" and k ~= "pcall" then -- HACK: remove "GetLibraryVersion" and such later. | |
487 local _, ret = pcall(AceLocale.error, lastSelf or self, "Translation %q does not exist.", k) | |
488 geterrorhandler()(ret) | |
489 return k | |
490 end | |
491 return nil | |
492 end | |
493 }) | |
494 | |
495 local function activate(self, oldLib, oldDeactivate) | |
496 AceLocale = self | |
497 | |
498 self.frame = oldLib and oldLib.frame or CreateFrame("Frame") | |
499 self.registry = oldLib and oldLib.registry or {} | |
500 self.BASE_TRANSLATIONS = oldLib and oldLib.BASE_TRANSLATIONS or {} | |
501 self.DEBUGGING = oldLib and oldLib.DEBUGGING or {} | |
502 self.TRANSLATIONS = oldLib and oldLib.TRANSLATIONS or {} | |
503 self.BASE_LOCALE = oldLib and oldLib.BASE_LOCALE or {} | |
504 self.TRANSLATION_TABLES = oldLib and oldLib.TRANSLATION_TABLES or {} | |
505 self.REVERSE_TRANSLATIONS = oldLib and oldLib.REVERSE_TRANSLATIONS or {} | |
506 self.STRICTNESS = oldLib and oldLib.STRICTNESS or {} | |
507 self.NAME = oldLib and oldLib.NAME or {} | |
508 self.DYNAMIC_LOCALES = oldLib and oldLib.DYNAMIC_LOCALES or {} | |
509 self.CURRENT_LOCALE = oldLib and oldLib.CURRENT_LOCALE or {} | |
510 self.reverseToBase = oldLib and oldLib.reverseToBase or {} | |
511 | |
512 BASE_TRANSLATIONS = self.BASE_TRANSLATIONS | |
513 DEBUGGING = self.DEBUGGING | |
514 TRANSLATIONS = self.TRANSLATIONS | |
515 BASE_LOCALE = self.BASE_LOCALE | |
516 TRANSLATION_TABLES = self.TRANSLATION_TABLES | |
517 REVERSE_TRANSLATIONS = self.REVERSE_TRANSLATIONS | |
518 STRICTNESS = self.STRICTNESS | |
519 NAME = self.NAME | |
520 DYNAMIC_LOCALES = self.DYNAMIC_LOCALES | |
521 CURRENT_LOCALE = self.CURRENT_LOCALE | |
522 | |
523 strict_instance_mt = { | |
524 __index = strict__index, | |
525 __newindex = __newindex, | |
526 __tostring = __tostring | |
527 } | |
528 | |
529 nonstrict_instance_mt = { | |
530 __index = nonstrict__index, | |
531 __newindex = __newindex, | |
532 __tostring = __tostring | |
533 } | |
534 | |
535 baseTranslations_mt = { | |
536 __index = AceLocale.prototype | |
537 } | |
538 | |
539 local GetTime = GetTime | |
540 local timeUntilClear = GetTime() + 5 | |
541 scheduleClear = function() | |
542 if next(newRegistries) then | |
543 self.frame:Show() | |
544 timeUntilClear = GetTime() + 5 | |
545 end | |
546 end | |
547 | |
548 for name, instance in pairs(self.registry) do | |
549 local name = name | |
550 setmetatable(instance, nil) | |
551 instance[NAME] = name | |
552 local strict | |
553 if instance[STRICTNESS] ~= nil then | |
554 strict = instance[STRICTNESS] | |
555 elseif instance[TRANSLATIONS] ~= instance[BASE_TRANSLATIONS] then | |
556 if getmetatable(instance[TRANSLATIONS]).__index == oldLib.prototype then | |
557 strict = true | |
558 end | |
559 end | |
560 instance[STRICTNESS] = strict and true or false | |
561 refixInstance(instance) | |
562 end | |
563 | |
564 self.frame:SetScript("OnEvent", scheduleClear) | |
565 self.frame:SetScript("OnUpdate", function() -- (this, elapsed) | |
566 if timeUntilClear - GetTime() <= 0 then | |
567 self.frame:Hide() | |
568 for k in pairs(newRegistries) do | |
569 clearCache(k) | |
570 newRegistries[k] = nil | |
571 k = nil | |
572 end | |
573 end | |
574 end) | |
575 self.frame:UnregisterAllEvents() | |
576 self.frame:RegisterEvent("ADDON_LOADED") | |
577 self.frame:RegisterEvent("PLAYER_ENTERING_WORLD") | |
578 self.frame:Show() | |
579 | |
580 if oldDeactivate then | |
581 oldDeactivate(oldLib) | |
582 end | |
583 end | |
584 | |
585 AceLibrary:Register(AceLocale, MAJOR_VERSION, MINOR_VERSION, activate) | |
586 --[[ | |
587 if true then -- debug | |
588 local L = AceLocale:new(MINOR_VERSION ~= 100000 and "AceLocale_DEBUG" or "AceLocale_DEBUG3") | |
589 L:RegisterTranslations("enUS", function() return { | |
590 Monkey = true, | |
591 House = true, | |
592 } end) | |
593 | |
594 L:RegisterTranslations("deDE", function() return { | |
595 Monkey = "Affe" | |
596 } end) | |
597 | |
598 L = AceLocale:new(MINOR_VERSION ~= 100000 and "AceLocale_DEBUG" or "AceLocale_DEBUG3") | |
599 assert(L.Monkey == "Monkey") | |
600 assert(L.House == "House") | |
601 if not L.Debug then | |
602 local pants = L.Pants | |
603 assert(not pants) | |
604 end | |
605 assert(L.Debug) | |
606 assert(L.Debug == AceLocale.prototype.Debug) | |
607 | |
608 if MINOR_VERSION == 100000 then | |
609 L = AceLocale:new("AceLocale_DEBUG") | |
610 assert(L.Monkey == "Monkey") | |
611 assert(L.House == "House") | |
612 assert(L.Debug) | |
613 assert(type(L.Debug) == "function") | |
614 assert(AceLocale.prototype.Debug) | |
615 assert(type(AceLocale.prototype.Debug) == "function") | |
616 assert(L.Debug == AceLocale.prototype.Debug) | |
617 end | |
618 | |
619 local L = AceLocale:new(MINOR_VERSION ~= 100000 and "AceLocale_DEBUG2" or "AceLocale_DEBUG4") | |
620 L:RegisterTranslations("deDE", function() return { | |
621 Affe = true, | |
622 Haus = true, | |
623 } end) | |
624 | |
625 L:RegisterTranslations("enUS", function() return { | |
626 Affe = "Monkey" | |
627 } end) | |
628 | |
629 L = AceLocale:new(MINOR_VERSION ~= 100000 and "AceLocale_DEBUG2" or "AceLocale_DEBUG4") | |
630 assert(L.Affe == "Monkey") | |
631 assert(L.Haus == "Haus") | |
632 assert(L.Debug) | |
633 assert(L.Debug == AceLocale.prototype.Debug) | |
634 | |
635 if MINOR_VERSION == 100000 then | |
636 L = AceLocale:new("AceLocale_DEBUG2") | |
637 assert(L.Affe == "Monkey") | |
638 assert(L.Haus == "Haus") | |
639 assert(L.Debug) | |
640 assert(L.Debug == AceLocale.prototype.Debug) | |
641 end | |
642 | |
643 local L = AceLocale:new(MINOR_VERSION ~= 100000 and "AceLocale_DEBUG5" or "AceLocale_DEBUG6") | |
644 L:RegisterTranslations("deDE", function() return { | |
645 Affe = true, | |
646 Haus = true, | |
647 } end) | |
648 | |
649 L:RegisterTranslations("enUS", function() return { | |
650 Affe = "Monkey" | |
651 } end) | |
652 | |
653 L:SetStrictness(true) | |
654 | |
655 L = AceLocale:new(MINOR_VERSION ~= 100000 and "AceLocale_DEBUG5" or "AceLocale_DEBUG6") | |
656 assert(L.Affe == "Monkey") | |
657 assert(L.Haus == "Haus") | |
658 assert(L.Debug) | |
659 assert(L.Debug == AceLocale.prototype.Debug) | |
660 | |
661 if MINOR_VERSION == 100000 then | |
662 L = AceLocale:new("AceLocale_DEBUG5") | |
663 assert(L.Affe == "Monkey") | |
664 assert(L.Haus == "Haus") | |
665 assert(L.Debug) | |
666 assert(L.Debug == AceLocale.prototype.Debug) | |
667 end | |
668 end | |
669 ]] |