comparison libs/AceLocale-2.2/AceLocale-2.2.lua @ 7:f920db5fc6b1

version 0.3
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:25:29 +0000
parents c11ca1d8ed91
children
comparison
equal deleted inserted replaced
6:2da5089ab7ff 7:f920db5fc6b1
1 --[[ 1 --[[
2 Name: AceLocale-2.2 2 Name: AceLocale-2.2
3 Revision: $Rev: 18708 $ 3 Revision: $Rev$
4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team) 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) 5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
6 Website: http://www.wowace.com/ 6 Website: http://www.wowace.com/
7 Documentation: http://www.wowace.com/index.php/AceLocale-2.2 7 Documentation: http://www.wowace.com/index.php/AceLocale-2.2
8 SVN: http://svn.wowace.com/root/trunk/Ace2/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 9 Description: Localization library for addons to use to handle proper
10 localization and internationalization. 10 localization and internationalization.
11 Dependencies: AceLibrary 11 Dependencies: AceLibrary
12 License: LGPL v2.1
12 ]] 13 ]]
13 14
14 local MAJOR_VERSION = "AceLocale-2.2" 15 local MAJOR_VERSION = "AceLocale-2.2"
15 local MINOR_VERSION = "$Revision: 18708 $" 16 local MINOR_VERSION = "$Revision: 20000 $"
16 17
17 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end 18 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
18 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end 19 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
19 20
20 local AceLocale = {} 21 local AceLocale = {}
214 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) 215 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)
215 end 216 end
216 end 217 end
217 end 218 end
218 rawset(self, CURRENT_LOCALE, locale) 219 rawset(self, CURRENT_LOCALE, locale)
220 if not rawget(self, 'reverse') then
221 rawset(self, 'reverse', setmetatable({}, { __index = function(self2, key)
222 local self = AceLocale.reverseToBase[self2]
223 if not rawget(self, REVERSE_TRANSLATIONS) then
224 self:GetReverseTranslation(key)
225 end
226 self.reverse = self[REVERSE_TRANSLATIONS]
227 return self.reverse[key]
228 end }))
229 AceLocale.reverseToBase[self.reverse] = self
230 end
219 refixInstance(self) 231 refixInstance(self)
220 if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then 232 if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then
221 if not rawget(self, TRANSLATION_TABLES) then 233 if not rawget(self, TRANSLATION_TABLES) then
222 rawset(self, TRANSLATION_TABLES, {}) 234 rawset(self, TRANSLATION_TABLES, {})
223 end 235 end
295 rawset(self, STRICTNESS, strict) 307 rawset(self, STRICTNESS, strict)
296 refixInstance(self) 308 refixInstance(self)
297 end 309 end
298 310
299 local function initReverse(self) 311 local function initReverse(self)
300 rawset(self, REVERSE_TRANSLATIONS, {}) 312 rawset(self, REVERSE_TRANSLATIONS, setmetatable({}, { __index = function(_, key)
313 AceLocale.error(self, "Reverse translation for %q does not exist", key)
314 end }))
301 local alpha = self[TRANSLATIONS] 315 local alpha = self[TRANSLATIONS]
302 local bravo = self[REVERSE_TRANSLATIONS] 316 local bravo = self[REVERSE_TRANSLATIONS]
303 for base, localized in pairs(alpha) do 317 for base, localized in pairs(alpha) do
304 bravo[localized] = base 318 bravo[localized] = base
305 end 319 end
378 AceLocale.error(self, "No translations registered") 392 AceLocale.error(self, "No translations registered")
379 end 393 end
380 initReverse(self) 394 initReverse(self)
381 x = self[REVERSE_TRANSLATIONS] 395 x = self[REVERSE_TRANSLATIONS]
382 end 396 end
383 return x[text] and true 397 return rawget(x, text) and true
384 end 398 end
385 399
386 function AceLocale.prototype:Debug() 400 function AceLocale.prototype:Debug()
387 if not rawget(self, DEBUGGING) then 401 if not rawget(self, DEBUGGING) then
388 return 402 return
391 local locales = {"enUS", "deDE", "frFR", "koKR", "zhCN", "zhTW", "esES"} 405 local locales = {"enUS", "deDE", "frFR", "koKR", "zhCN", "zhTW", "esES"}
392 local localizations = {} 406 local localizations = {}
393 DEFAULT_CHAT_FRAME:AddMessage("--- AceLocale Debug ---") 407 DEFAULT_CHAT_FRAME:AddMessage("--- AceLocale Debug ---")
394 for _,locale in ipairs(locales) do 408 for _,locale in ipairs(locales) do
395 if not self[TRANSLATION_TABLES][locale] then 409 if not self[TRANSLATION_TABLES][locale] then
396 DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q not found", locale)) 410 DEFAULT_CHAT_FRAME:AddMessage(("Locale %q not found"):format(locale))
397 else 411 else
398 localizations[locale] = self[TRANSLATION_TABLES][locale] 412 localizations[locale] = self[TRANSLATION_TABLES][locale]
399 end 413 end
400 end 414 end
401 local localeDebug = {} 415 local localeDebug = {}
433 end 447 end
434 end 448 end
435 end 449 end
436 for locale, t in pairs(localeDebug) do 450 for locale, t in pairs(localeDebug) do
437 if not next(t) then 451 if not next(t) then
438 DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q complete", locale)) 452 DEFAULT_CHAT_FRAME:AddMessage(("Locale %q complete"):format(locale))
439 else 453 else
440 DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q missing:", locale)) 454 DEFAULT_CHAT_FRAME:AddMessage(("Locale %q missing:"):format(locale))
441 for word in pairs(t) do 455 for word in pairs(t) do
442 DEFAULT_CHAT_FRAME:AddMessage(string.format(" %q", word)) 456 DEFAULT_CHAT_FRAME:AddMessage((" %q"):format(word))
443 end 457 end
444 end 458 end
445 end 459 end
446 DEFAULT_CHAT_FRAME:AddMessage("--- End AceLocale Debug ---") 460 DEFAULT_CHAT_FRAME:AddMessage("--- End AceLocale Debug ---")
447 end 461 end
468 self.REVERSE_TRANSLATIONS = oldLib and oldLib.REVERSE_TRANSLATIONS or {} 482 self.REVERSE_TRANSLATIONS = oldLib and oldLib.REVERSE_TRANSLATIONS or {}
469 self.STRICTNESS = oldLib and oldLib.STRICTNESS or {} 483 self.STRICTNESS = oldLib and oldLib.STRICTNESS or {}
470 self.NAME = oldLib and oldLib.NAME or {} 484 self.NAME = oldLib and oldLib.NAME or {}
471 self.DYNAMIC_LOCALES = oldLib and oldLib.DYNAMIC_LOCALES or {} 485 self.DYNAMIC_LOCALES = oldLib and oldLib.DYNAMIC_LOCALES or {}
472 self.CURRENT_LOCALE = oldLib and oldLib.CURRENT_LOCALE or {} 486 self.CURRENT_LOCALE = oldLib and oldLib.CURRENT_LOCALE or {}
487 self.reverseToBase = oldLib and oldLib.reverseToBase or {}
473 488
474 BASE_TRANSLATIONS = self.BASE_TRANSLATIONS 489 BASE_TRANSLATIONS = self.BASE_TRANSLATIONS
475 DEBUGGING = self.DEBUGGING 490 DEBUGGING = self.DEBUGGING
476 TRANSLATIONS = self.TRANSLATIONS 491 TRANSLATIONS = self.TRANSLATIONS
477 BASE_LOCALE = self.BASE_LOCALE 492 BASE_LOCALE = self.BASE_LOCALE