Easily localize an addon
From WoWWiki
(Redirected from HOWTO: Localize an addon easily)
This page will provide some guidelines on how you can easily set up your addon to be localized.
Contents |
Overall layout
This design separates localization files for each locale, like Localization.enUS.lua. Each file holds the localized strings for that locale. Inside the main addon files I reference the localization table as a local variable. Provided next will be examples.
Localization.enUS.lua
The main localization file which all the others will pull from. Code:
local debug = false
MyLocalization = setmetatable({
['String 1'] = 'String 1',
['String 2'] = 'String 2',
['More strings here'] = 'More string here',
}, {__index = function(self, key)
if debug then ChatFrame3:AddMessage('Please localize: '..tostring(key)) end
rawset(self, key, key)
return key
end })
This code generates a localized table that can optionally inform you when there is a key is not localized.
MyAddon.lua
Code:
local L = MyLocalization ChatFrame1:AddMessage(L['Welcome to WoW!']) -- this should provide an extra message if you have debug set to true. ChatFrame1:AddMessage(L['More strings here']) -- here it shouldn't provide any other messages
Localization.deDE.lua
Code:
if GetLocale() ~= "deDE" then return end
MyLocalization = setmetatable({
['String 1'] = 'Localized string 1',
}, {__index = MyLocalization})
This localization will fall back onto the other localization.
MyAddon.toc
Code:
MyLocalization.enUS.lua MyLocalization.deDE.lua MyAddon.lua
See Also: HOWTO: Localize an Addon
