From 8e8f8e7608caf1ec55e2a5fd6bf99fbc1b5fd9c5 Mon Sep 17 00:00:00 2001 From: Tekkub Stoutwrithe Date: Wed, 28 Nov 2007 23:55:50 -0700 Subject: [PATCH] Adding magic localization table, deDE locale strings from decimad See Issue #125 --- Locale.lua | 25 +++++++++++++++++++++++++ Mapping.lua | 3 ++- OHFrame.lua | 5 +++-- QuestTracking.lua | 9 +++++---- TourGuide.lua | 7 +++++-- TourGuide.toc | 1 + UnlistedQuest.lua | 3 ++- 7 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 Locale.lua diff --git a/Locale.lua b/Locale.lua new file mode 100644 index 0000000..2696877 --- /dev/null +++ b/Locale.lua @@ -0,0 +1,25 @@ + +local localized + +local engrish = { + PART_GSUB = "%s%(Part %d+%)", + PART_FIND = "(.+)%s%(Part %d+%)", + + -- Mapping.lua + COORD_MATCH = "%(([%d.]+),%s?([%d.]+)%)", +} + + +if GetLocale() == "deDE" then localized = { + PART_GSUB = "%s%(Teil %d+%)", + PART_FIND = "(.+)%s%(Teil %d+%)", + ["(.*) is now your home."] = "(.*) ist jetzt Euer Zuhause.", + ["Quest accepted: (.*)"] = "Quest angenommen: (.*)", + ["^You .*Hitem:(%d+).*(%[.+%])"] = "^Ihr .*Hitem:(%d+).*(%[.+%])", +} end + + +-- Metatable majicks... makes localized table fallback to engrish, or fallback to the index requested. +-- This ensures we ALWAYS get a value back, even if it's the index we requested originally +TOURGUIDE_LOCALE = localized and setmetatable(localized, {__index = function(t,i) return engrish[i] or i end}) + or setmetatable(engrish, {__index = function(t,i) return i end}) diff --git a/Mapping.lua b/Mapping.lua index 32a1edd..c7fce0f 100644 --- a/Mapping.lua +++ b/Mapping.lua @@ -1,4 +1,5 @@ +local L = TourGuide.Locale local zonei, zonec = {}, {} for ci,c in pairs{GetMapContinents()} do @@ -23,7 +24,7 @@ end function TourGuide:ParseAndMapCoords(note, desc, zone) - for x,y in note:gmatch("%(([%d.]+),%s?([%d.]+)%)") do MapPoint(zone, tonumber(x), tonumber(y), desc) end + for x,y in note:gmatch(L.COORD_MATCH) do MapPoint(zone, tonumber(x), tonumber(y), desc) end end diff --git a/OHFrame.lua b/OHFrame.lua index b22fb50..8a709fa 100644 --- a/OHFrame.lua +++ b/OHFrame.lua @@ -1,6 +1,7 @@ local TourGuide = TourGuide +local L = TourGuide.Locale local ww = WidgetWarlock @@ -116,7 +117,7 @@ function TourGuide:UpdateOHPanel(value) for i in pairs(self.actions) do local action, name = self:GetObjectiveInfo(i) - local _, _, quest, part = name:find("(.+)%s%(Part %d+%)") + local _, _, quest, part = name:find(L.PART_FIND) if quest and not accepted[quest] and not self:GetObjectiveStatus(i) then accepted[quest] = name end end @@ -128,7 +129,7 @@ function TourGuide:UpdateOHPanel(value) local turnedin, logi, complete = self:GetObjectiveStatus(i + offset) row:Show() - local shortname = name:gsub("%s%(Part %d+%)", "") + local shortname = name:gsub(L.PART_GSUB, "") logi = not turnedin and (not accepted[shortname] or (accepted[shortname] == name)) and logi complete = not turnedin and (not accepted[shortname] or (accepted[shortname] == name)) and complete local checked = turnedin or action == "ACCEPT" and logi or action == "COMPLETE" and complete diff --git a/QuestTracking.lua b/QuestTracking.lua index 89a1bfd..27f8f78 100644 --- a/QuestTracking.lua +++ b/QuestTracking.lua @@ -1,6 +1,7 @@ local TourGuide = TourGuide +local L = TourGuide.Locale local hadquest @@ -41,7 +42,7 @@ function TourGuide:CHAT_MSG_SYSTEM(event, msg) local action, quest = self:GetObjectiveInfo() if action == "SETHEARTH" then - local _, _, loc = msg:find("(.*) is now your home.") + local _, _, loc = msg:find(L["(.*) is now your home."]) if loc and loc == quest then self:DebugF(1, "Detected setting hearth to %q", loc) return self:SetTurnedIn() @@ -49,8 +50,8 @@ function TourGuide:CHAT_MSG_SYSTEM(event, msg) end if action == "ACCEPT" then - local _, _, text = msg:find("Quest accepted: (.*)") - if text and quest:gsub("%s%(Part %d+%)", "") == text then + local _, _, text = msg:find(L["Quest accepted: (.*)"]) + if text and quest:gsub(L.PART_GSUB, "") == text then self:DebugF(1, "Detected quest accept %q", quest) return self:UpdateStatusFrame() end @@ -84,7 +85,7 @@ end function TourGuide:CHAT_MSG_LOOT(event, msg) local action, quest = self:GetObjectiveInfo() local lootitem, lootqty = self:GetObjectiveTag("L") - local _, _, itemid, name = msg:find("^You .*Hitem:(%d+).*(%[.+%])") + local _, _, itemid, name = msg:find(L["^You .*Hitem:(%d+).*(%[.+%])"]) self:Debug(10, event, action, quest, lootitem, lootqty, itemid, name) if action == "BUY" and name and name == quest diff --git a/TourGuide.lua b/TourGuide.lua index 9300e2d..f554dac 100644 --- a/TourGuide.lua +++ b/TourGuide.lua @@ -3,12 +3,15 @@ local OptionHouse = LibStub("OptionHouse-1.1") local myfaction = UnitFactionGroup("player") +local L = TOURGUIDE_LOCALE +TOURGUIDE_LOCALE = nil TourGuide = DongleStub("Dongle-1.0"):New("TourGuide") if tekDebug then TourGuide:EnableDebug(10, tekDebug:GetFrame("TourGuide")) end TourGuide.guides = {} TourGuide.guidelist = {} TourGuide.nextzones = {} +TourGuide.Locale = L TourGuide.icons = setmetatable({ @@ -84,7 +87,7 @@ end function TourGuide:GetQuestLogIndexByName(name) name = name or self.quests[self.current] - name = name:gsub("%s%(Part %d+%)", "") + name = name:gsub(L.PART_GSUB, "") for i=1,GetNumQuestLogEntries() do if GetQuestLogTitle(i) == name then return i end end @@ -150,7 +153,7 @@ function TourGuide:CompleteQuest(name, noupdate) local action, quest repeat action, quest = self:GetObjectiveInfo(i) - if action == "TURNIN" and not self:GetObjectiveStatus(i) and name == quest:gsub("%s%(Part %d+%)", "") then + if action == "TURNIN" and not self:GetObjectiveStatus(i) and name == quest:gsub(L.PART_GSUB, "") then self:DebugF(1, "Saving quest turnin %q", quest) return self:SetTurnedIn(i, true, noupdate) end diff --git a/TourGuide.toc b/TourGuide.toc index 08d544f..34ce05e 100755 --- a/TourGuide.toc +++ b/TourGuide.toc @@ -19,6 +19,7 @@ Dongle.lua OptionHouse.lua WidgetWarlock.lua +Locale.lua TourGuide.lua Parser.lua Mapping.lua diff --git a/UnlistedQuest.lua b/UnlistedQuest.lua index e6ca998..1fd6f1d 100644 --- a/UnlistedQuest.lua +++ b/UnlistedQuest.lua @@ -1,10 +1,11 @@ local TourGuide = TourGuide +local L = TourGuide.Locale function TourGuide:IsQuestAcceptable(name) for i,v in pairs(self.actions) do - if (v == "ACCEPT" or v == "COMPLETE") and self.quests[i]:gsub("%s%(Part %d+%)", "") == name then return true end + if (v == "ACCEPT" or v == "COMPLETE") and self.quests[i]:gsub(L.PART_GSUB, "") == name then return true end end end -- 2.11.4.GIT