View Single Post
02-09-12, 06:13 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Localization.lua, load first in TOC:
Code:
local ADDON_NAME, addon = ...

local L = setmetatable({}, { __index = function(t, k)
	local v = tostring(k)
	rawset(t, k, v)
	return v
end })
addon.L = L

local LOCALE = GetLocale()

if LOCALE:match("^en") then
	-- No need to specify English translations
	-- since you are using the English text as
	-- the table key.
	-- Also no need to check other locales if
	-- this is an English client.
return end

-- German
if LOCALE == "deDE" then
	-- Binding Headers
	L["Raid Targeting Mouseover"] = "Überfall Ziel Mausüber"
	L["World Target / Flares"] = "Welt Ziel / Flare"
	L["Sound"] = "Klingen"
	L["Temporary Mute"] = "Temporäre Stummschaltung"
	L["Toggle Mute"] = "Stummschaltung"
	L["Blue Flare"] = "Blau Flare"
	L["Green Flare"] = "Grüne Flare"
	L["Purple Flare"] = "Lila Flare"
	L["Red Flare"] = "Rot Flare"
	L["Yellow Flare"] = "Gelb Flare"
	L["Clear all World Targets"] = "Löschen aller Welt Ziele"
return end

-- Spanish
if LOCALE == "esES" or LOCALE == "esMX" then
	-- Spanish translations here
end

-- other translations etc.
Other files:
Code:
local ADDON_NAME, addon = ...
local L = addon.L

blah:SetText(L["Blahblah"])
The heart of his method is 5 lines/105 bytes of code, vs 74 lines/2.25 kb for AceLocale (even after comments and blank lines are removed). Static memory is not critical, but why use 22x the code for the same end result with no meaningful benefits along the way?

Also:

You shouldn't need to check for the addon in LoD modules; just make sure the core addon is listed as a dependency in the module's TOC:
Code:
## LoadOnDemand: 1
## Dependencies: GrimUI
This will prevent the addon from ever being loaded if the GrimUI addon is not already loaded.

Last edited by Phanx : 02-09-12 at 06:20 PM.
  Reply With Quote