The common texts in tooltips (X mana, Y rage, Z energy, etc.) all use
strings from GlobalStrings.lua, so you can just pick out the strings (Blizzard uses them with string.format) and convert them for use with string.match.
For example, the "X mana" string is contained in the global variable MANA_COST, and I use the following code to make spell tooltips show the mana costs of spells as a percent of my total mana pool instead of as a raw number; the lines I highlighted in green will be the most relevant for you.
Code:
local MANA_COST_PATTERN = gsub(MANA_COST, "%%d", "([%%d%.,]+)")
local MANA_COST_TEXT = gsub(MANA_COST, "%%d", "%%d%%%%")
GameTooltip:HookScript("OnTooltipSetSpell", function()
for i = 2, 4 do
local line = _G["GameTooltipTextLeft"..i]
local text = line:GetText()
if text then
local cost = strmatch(text, MANA_COST_PATTERN)
cost = cost and tonumber((gsub(cost, "%D", "")))
if cost then
local pool = UnitPowerMax(UnitInVehicle("player") and "vehicle" or "player")
if cost > 0 and cost <= pool then
return line:SetFormattedText(MANA_COST_TEXT, cost / pool * 100 + 0.5)
end
return
end
end
end
end)
Edit: You will need to do a little more work to "patternize" strings with singular/plural variations, but you should be able to figure it out pretty easily by looking at the global strings for each locale (link above).