This is a perfect use-case for a metatable and tooltip scanning:
Code:
local MyScanningTooltip = CreateFrame("GameTooltip", "MyScanningTooltip", UIParent, "GameTooltipTemplate")
local QuestTitleFromID = setmetatable({}, { __index = function(t, id)
MyScanningTooltip:SetOwner(UIParent, "ANCHOR_NONE")
MyScanningTooltip:SetHyperlink("quest:"..id)
local title = MyScanningTooltipTextLeft1:GetText()
MyScanningTooltip:Hide()
if title and title ~= RETRIEVING_DATA then
t[id] = title
return title
end
end })
Put that at/near the top of your file, and then just do a simple table lookup with the ID to get the name:
Code:
print(QuestTitleFromID[30318])
-- prints "Chasing the Chicken"
If the ID is invalid, or your game client doesn't have the info yet and has to query the server (not sure if this can even happen for quests), you will get
nil instead of the quest name; if you're sure your ID was valid, you can just look it up again and your client should have the data by then.
You can use the same technique to get the localized name of anything else where there is no relevant API (eg. if you want item or spell names, just use
GetItemInfo or
GetSpellInfo). For example, there was
recently a thread demonstrating this technique for getting localized NPC names from their mobIDs.