diff 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
line wrap: on
line diff
--- a/libs/AceLocale-2.2/AceLocale-2.2.lua	Tue Mar 20 21:20:20 2007 +0000
+++ b/libs/AceLocale-2.2/AceLocale-2.2.lua	Tue Mar 20 21:25:29 2007 +0000
@@ -1,6 +1,6 @@
 --[[
 Name: AceLocale-2.2
-Revision: $Rev: 18708 $
+Revision: $Rev$
 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
 Website: http://www.wowace.com/
@@ -9,10 +9,11 @@
 Description: Localization library for addons to use to handle proper
              localization and internationalization.
 Dependencies: AceLibrary
+License: LGPL v2.1
 ]]
 
 local MAJOR_VERSION = "AceLocale-2.2"
-local MINOR_VERSION = "$Revision: 18708 $"
+local MINOR_VERSION = "$Revision: 20000 $"
 
 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
@@ -216,6 +217,17 @@
 		end
 	end
 	rawset(self, CURRENT_LOCALE, locale)
+	if not rawget(self, 'reverse') then
+		rawset(self, 'reverse', setmetatable({}, { __index = function(self2, key)
+			local self = AceLocale.reverseToBase[self2]
+			if not rawget(self, REVERSE_TRANSLATIONS) then
+				self:GetReverseTranslation(key)
+			end
+			self.reverse = self[REVERSE_TRANSLATIONS]
+			return self.reverse[key]
+		end }))
+		AceLocale.reverseToBase[self.reverse] = self
+	end
 	refixInstance(self)
 	if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then
 		if not rawget(self, TRANSLATION_TABLES) then
@@ -297,7 +309,9 @@
 end
 
 local function initReverse(self)
-	rawset(self, REVERSE_TRANSLATIONS, {})
+	rawset(self, REVERSE_TRANSLATIONS, setmetatable({}, { __index = function(_, key)
+		AceLocale.error(self, "Reverse translation for %q does not exist", key)
+	end }))
 	local alpha = self[TRANSLATIONS]
 	local bravo = self[REVERSE_TRANSLATIONS]
 	for base, localized in pairs(alpha) do
@@ -380,7 +394,7 @@
 		initReverse(self)
 		x = self[REVERSE_TRANSLATIONS]
 	end
-	return x[text] and true
+	return rawget(x, text) and true
 end
 
 function AceLocale.prototype:Debug()
@@ -393,7 +407,7 @@
 	DEFAULT_CHAT_FRAME:AddMessage("--- AceLocale Debug ---")
 	for _,locale in ipairs(locales) do
 		if not self[TRANSLATION_TABLES][locale] then
-			DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q not found", locale))
+			DEFAULT_CHAT_FRAME:AddMessage(("Locale %q not found"):format(locale))
 		else
 			localizations[locale] = self[TRANSLATION_TABLES][locale]
 		end
@@ -435,11 +449,11 @@
 	end
 	for locale, t in pairs(localeDebug) do
 		if not next(t) then
-			DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q complete", locale))
+			DEFAULT_CHAT_FRAME:AddMessage(("Locale %q complete"):format(locale))
 		else
-			DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q missing:", locale))
+			DEFAULT_CHAT_FRAME:AddMessage(("Locale %q missing:"):format(locale))
 			for word in pairs(t) do
-				DEFAULT_CHAT_FRAME:AddMessage(string.format("    %q", word))
+				DEFAULT_CHAT_FRAME:AddMessage(("    %q"):format(word))
 			end
 		end
 	end
@@ -470,6 +484,7 @@
 	self.NAME = oldLib and oldLib.NAME or {}
 	self.DYNAMIC_LOCALES = oldLib and oldLib.DYNAMIC_LOCALES or {}
 	self.CURRENT_LOCALE = oldLib and oldLib.CURRENT_LOCALE or {}
+	self.reverseToBase = oldLib and oldLib.reverseToBase or {}
 	
 	BASE_TRANSLATIONS = self.BASE_TRANSLATIONS
 	DEBUGGING = self.DEBUGGING