WoW:Localizing an addon: Difference between revisions

m
Line 9: Line 9:
The locale is what makes it possible to know what language the interface is using and thus determine which specific code is going to be executed in a localized addon.
The locale is what makes it possible to know what language the interface is using and thus determine which specific code is going to be executed in a localized addon.


typically, this is used in a GetLocale block:
typically, this is used in a [[API_GetLocale|GetLocale]] block:


Code:
Code:
Line 17: Line 17:
         -- for the rest, usually english since it's the default language
         -- for the rest, usually english since it's the default language
     end
     end
"frFR": french
"deDE": german
"enUS": english
"koKR": korean


== Variables ==
== Variables ==
Line 175: Line 170:


in the french client you have the following order:
in the french client you have the following order:
     Ashenvale, Azshara, Un'Goro Crater (translated as "Cratère d'Un'Goro"), etc.
     Ashenvale, Azshara, Un'Goro Crater (translated as "Cratère d'Un'Goro"), etc.


3rd entry represent a different zone.  
3rd entry represent a different zone.  
Line 208: Line 203:
The -frFR postfix indicate to a french localized client that a translation is available and should be prefered to the default (which most of the time correspond to english), if no "localized" entry exists for a specific client, the default one is displayed.
The -frFR postfix indicate to a french localized client that a translation is available and should be prefered to the default (which most of the time correspond to english), if no "localized" entry exists for a specific client, the default one is displayed.


Addendum (patch 1.4.0): in patch 1.4.0 a slightly cryptic comment from Slouken on the US board announce that they left the decimal point to the european value (ie a coma). The impact of this is that table index that uses a strings containing a dot do not work anymore, since that behaviour didn't exist before patch 1.4.0 on european version, caution would be avoid using dots in text index for table.
Addendum (patch 1.4.0): in patch 1.4.0 a slightly cryptic comment from Slouken on the US board announce that they left the decimal point to the european value (ie a comma). The impact of this is that table index that uses a strings containing a dot do not work anymore, since that behaviour didn't exist before patch 1.4.0 on european version, caution would be avoid using dots in text index for table.


Exemple: prior to patch this table was fine.
Exemple: prior to patch this table was fine.
Line 214: Line 209:


Post patch, trying get the index content would result in an error because it was translated by the game engine to "FR 1,4,0" which of course doesn't match the index up there.
Post patch, trying get the index content would result in an error because it was translated by the game engine to "FR 1,4,0" which of course doesn't match the index up there.
== Some tips ==
Here are some of Sarf's tips that can be used to keep addons localized during maintenance and updates.
See the [[Localization_Info|Localization Information]] page for lists of known localized strings (zones, channels, etc.)
=== Do not use item names ===
Q: How do you refer to items if not by their names?
A: By using their item ids.
Thanks to CastOptions.lua for the origin of this code snippet:
function MyAddOn_ExtractItemID(link)
_, _, id = string.find(link, "Hitem:(.+):%d+:%d+:%d+%\124");
return id;
end
If you are wondering how to get item links, check out the [[World of Warcraft API#Item Functions|Global API - Item Functions]].
=== Use predefined, global names for skills ===
By using predefined, global names for skills you can change the skill on-the-fly as well as not have to care what the name actually is!
Do remember to keep rank and spell name seperate, however. This allows for easy integration with [[API GetSpellName|GetSpellName(spellID, "bookType")]].
=== Seperate localization code/variables from normal code ===
Usually, one file per language / locale is about right.
The naming convention is often localization<SEPERATOR><LOCALE>.lua
Examples (German localization):
localization.de.lua
or
localization_de.lua
You can have empty localization file, or you can just put this into them:
if ( GetLocale() == "deDE" ) then
    -- todo
end
[[Category: HOWTOs|Localize an AddOn]]