Originally Posted by Rainrider
Based on Phanx proposal my code currently looks like this:
lua Code:
if (UnitIsDead(unit)) then return _G["DEAD"] elseif (UnitIsGhost(unit)) then local ghost = GetSpellInfo(8326) if (GetLocale() == "deDE") then ghost = ghost:sub(1, 5) end return ghost elseif (not UnitIsConnected(unit)) then return _G["PLAYER_OFFLINE"] end
|
Instead of truncating the string, you can have your code override the translation on load. The following example uses the localized spell name, then checks for specific locales to see if it needs to be changed. Replacing the entire string with a new one is less taxing on the system and if they ever decide to change the translation, it won't be screwed up.
Lua Code:
local GHOST,Locale=GetSpellInfo(8326),GetLocale();
if Locale=="deDE" then
GHOST="Geist";
end
local function UnitDeadText(unit)
if UnitIsDead(unit) then
return DEAD;
elseif UnitIsGhost(unit) then
return GHOST;
elseif not UnitIsConnected(unit) then
return PLAYER_OFFLINE;
end
end
Another performance issue I fixed; unless the table field is an invalid variable name or you need to access a series of names based on a looping mechanism or any dynamic method, you should avoid using
_G[].
To better understand this problem, Lua operates by looking through locals first, upvalues (locals in a higher scope), and finally global. When accessing a global by
_G[], you're telling Lua to access the global list for a copy of itself, then access your variable.