Quantcast

Localizing base expression list

Erik L. Vonderscheer [07-02-09 - 08:13]
Localizing base expression list
Filename
TradeFilter3.lua
TradeFilter3Locale.lua
TradeFilter3Options.lua
diff --git a/TradeFilter3.lua b/TradeFilter3.lua
index 7405869..45c422f 100644
--- a/TradeFilter3.lua
+++ b/TradeFilter3.lua
@@ -33,6 +33,7 @@ File Date: @file-date-iso@
 --]]

 TradeFilter3 = LibStub("AceAddon-3.0"):NewAddon("TradeFilter3", "AceConsole-3.0", "AceEvent-3.0")
+local L =  LibStub("AceLocale-3.0"):GetLocale("TradeFilter3", true)
 local friends = LibStub("LibFriends-1.0")
 local TF3 = TradeFilter3

@@ -68,31 +69,7 @@ defaults = {
 		filterTrade = true,
 		addfilter_enable = false,
 		friendslist = {},
-		filter = {
-			"CUSTOM FILTER 1",
-			"CUSTOM FILTER 2",
-			"CUSTOM FILTER 3",
-			"[lL][fF] [pP][oO][rR][tT]",
-			"[bB][uU][yY][iI][nN][gG]",
-			"[wW][tT][bBsStT]",
-			"[lL][fF][wWeEmM]",
-			"[lL][fF] [eE][nN][cC][hH][aA][nN][tT]",
-			"[lL][fF] [jJ][cC]",
-			"[lL][fF] [dD][pP][sS]",
-			"[lL][fF] [tT][aA][nN][kK]",
-			"[lL][fF] [hH][eE][aA][lL][eE][rR]",
-			"[lL][fF]%d[mM]?",
-			"[lL][fF][mM]?",
-			"[lL][fF][gG]",
-			"AH",
-			"looking for work",
-			"lockpick",
-			"[sS][eE][lL][lL][iI][nN][gG]",
-			"[bB][uU][yY][iI][nN][gG]",
-			"2[vV]2",
-			"3[vV]3",
-			"5[vV]5"
-    }
+		filter = L.FILTER
 	}
 }

@@ -100,7 +77,6 @@ function TF3:OnInitialize()
 	--[[ Libraries ]]--
 	local ACD = LibStub("AceConfigDialog-3.0")
 	local LAP = LibStub("LibAboutPanel")
-	local L =  LibStub("AceLocale-3.0"):GetLocale("TradeFilter3", true)

 	self.db = LibStub("AceDB-3.0"):New("TradeFilter3DB", defaults);

@@ -313,38 +289,20 @@ function TF3:FilterFunc(...)
 			TF3:FindFrame(debugFrame, "arg1: " .. arg1 .. " arg2: " .. arg2)
 		end
 		--@end-alpha@
-		if (self.db.profile.addfilter_enable) then
-			for i,v in ipairs(self.db.profile.filter) do
-				--@alpha@
-				if (self.db.profile.debug) then
-					TF3:FindFrame(debugFrame, "Checking for Match with " .. v)
-				end
-				--@end-alpha@
-				if (find(arg1,v)) then
-					--@alpha@
-					if (self.db.profile.debug) then
-						TF3:FindFrame(debugFrame, "|cff00ff00**** Matched ***|r")
-					end
-					--@end-alpha@
-				filtered = false
-				end
+		for i,v in pairs(self.db.profile.filter) do
+			--@alpha@
+			if (self.db.profile.debug) then
+				TF3:FindFrame(debugFrame, "Checking for Match with " .. v)
 			end
-		else
-			for i=4,#self.db.profile.filter do
+			--@end-alpha@
+			if (find(arg1,v)) then
 				--@alpha@
 				if (self.db.profile.debug) then
-					TF3:FindFrame(debugFrame, "Checking for Match with " .. self.db.profile.filter[i])
+					TF3:FindFrame(debugFrame, "|cff00ff00**** Matched ***|r")
 				end
 				--@end-alpha@
-				if (find(arg1, self.db.profile.filter[i])) then
-					--@alpha@
-					if (self.db.profile.debug) then
-						TF3:FindFrame(debugFrame, "|cff00ff00**** Matched ***|r")
-					end
-					--@end-alpha@
-				filtered = false
-				end
-			end
+			filtered = false
+			end
 		end
 		if (filtered == true) then
 			if (lastArg1 ~= arg1 or lastArg2 ~= arg2) then
diff --git a/TradeFilter3Locale.lua b/TradeFilter3Locale.lua
index 60df1e0..fe5210f 100644
--- a/TradeFilter3Locale.lua
+++ b/TradeFilter3Locale.lua
@@ -10,30 +10,30 @@ debug = true

 local L =  LibStub("AceLocale-3.0"):NewLocale("TradeFilter3", "enUS", true)
 if L then
---@localization(locale="enUS", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="concat")@
+--@localization(locale="enUS", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="subtable")@
 if GetLocale() == "enUS" then return end
 end

 local L =  LibStub("AceLocale-3.0"):NewLocale("TradeFilter3", "deDE")
 if L then
---@localization(locale="deDE", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="concat")@
+--@localization(locale="deDE", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="subtable")@
 if GetLocale() == "deDE" then return end
 end

 local L =  LibStub("AceLocale-3.0"):NewLocale("TradeFilter3", "zhCN")
 if L then
---@localization(locale="zhCN", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="concat")@
+--@localization(locale="zhCN", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="subtable")@
 if GetLocale() == "zhCN" then return end
 end

 local L =  LibStub("AceLocale-3.0"):NewLocale("TradeFilter3", "zhTW")
 if L then
---@localization(locale="zhTW", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="concat")@
+--@localization(locale="zhTW", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="subtable")@
 if GetLocale() == "zhTW" then return end
 end

 local L =  LibStub("AceLocale-3.0"):NewLocale("TradeFilter3", "frFR")
 if L then
---@localization(locale="frFR", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="concat")@
+--@localization(locale="frFR", format="lua_additive_table", same-key-is-true=true, handle-subnamespaces="subtable")@
 if GetLocale() == "frFR" then return end
 end
diff --git a/TradeFilter3Options.lua b/TradeFilter3Options.lua
index 019ac23..ac482b3 100644
--- a/TradeFilter3Options.lua
+++ b/TradeFilter3Options.lua
@@ -136,11 +136,16 @@ options = {
 							name = L["AddFilter1"],
 							desc = L["AddFilter1D"],
 							get = function(info)
-								return TF3.db.profile.filter[1]
+								return TF3.db.profile.filter["20"]
 							end,
 							set = function(info, value)
-								TF3.db.profile.filter[1] = value
-								print(format("%s added to filter expression list.", value))
+								if (value == "") then
+									TF3.db.profile.filter["20"] = nil
+									print("Expression removed from custom filter list.")
+								else
+									TF3.db.profile.filter["20"] = value
+									print(format("%s added to filter expression list.", value))
+								end
 							end,
 							usage = L["AddFilterUsage"],
 						},
@@ -154,11 +159,16 @@ options = {
 							name = L["AddFilter2"],
 							desc = L["AddFilter1D"],
 							get = function(info)
-								return TF3.db.profile.filter[2]
+								return TF3.db.profile.filter["21"]
 							end,
 							set = function(info, value)
-								TF3.db.profile.filter[2] = value
-								print(format("%s added to filter expression list.", value))
+								if (value == "") then
+									TF3.db.profile.filter["21"] = nil
+									print("Expression removed from custom filter list.")
+								else
+									TF3.db.profile.filter["21"] = value
+									print(format("%s added to filter expression list.", value))
+								end
 							end,
 							usage = L["AddFilterUsage"],
 						},
@@ -172,11 +182,16 @@ options = {
 							name = L["AddFilter3"],
 							desc = L["AddFilter1D"],
 							get = function(info)
-								return TF3.db.profile.filter[3]
+								return TF3.db.profile.filter["22"]
 							end,
 							set = function(info, value)
-								TF3.db.profile.filter[3] = value
-								print(format("%s added to filter expression list.", value))
+								if (value == "") then
+									TF3.db.profile.filter["22"] = nil
+									print("Expression removed from custom filter list.")
+								else
+									TF3.db.profile.filter["22"] = value
+									print(format("%s added to filter expression list.", value))
+								end
 							end,
 							usage = L["AddFilterUsage"],
 						},