WoW:Localizing an addon: Difference between revisions

m
Move page script moved page Localizing an addon to WoW:Localizing an addon without leaving a redirect
(→‎localization.core.lua: break comment into multiple lines)
m (Move page script moved page Localizing an addon to WoW:Localizing an addon without leaving a redirect)
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{UIHowTo}}
{{wow/uihowto}}
Blizzard releases many localized versions of the World of Warcraft client, each version translating the game to a particular language. Players in some regions may also install additional [http://www.wow-europe.com/en/downloads/elp/ language packs], allowing them to play World of Warcraft in a desired language.
Blizzard releases many localized versions of the World of Warcraft client, each version translating the game to a particular language. Players in some regions may also install additional [http://www.wow-europe.com/en/downloads/elp/ language packs], allowing them to play World of Warcraft in a desired language.


Line 38: Line 38:


=== Localization in the .toc file ===
=== Localization in the .toc file ===
A number of [[TOC format#Official tags|official .toc tags]] support localization by appending a locale suffix to a tag name. This mechanism allows addons to present a localized name and description of the addon in the addons interface. The following example illustrates this, by adding a french ("frFR" locale) title and description to the Gatherer addon:
#A number of [[TOC format#Official tags|official .toc tags]] support localization by appending a locale suffix to a tag name. This mechanism allows addons to present a localized name and description of the addon in the addons interface. The following example illustrates this, by adding a french ("frFR" locale) title and description to the Gatherer addon:
  Title: Gatherer
  Title: Gatherer
  Title-frFR: Gatherer (en Francais, in French)
  Title-frFR: Gatherer (en Francais, in French)
  Notes: Gatherer, displays stuff you gather in your minimap
  Notes: Gatherer, displays stuff you gather in your minimap
  Notes-frFR: Gatherer, affiche les objets recoltes dans la minicarte
  Notes-frFR: Gatherer, affiche les objets recoltés dans la minicarte


=== Making an addon localizable ===
=== Making an addon localizable ===
To begin with, you need to ensure that every time your addon displays a piece of text to the user, that piece of text ''can'' be localized. Consider the two pieces of code below:
To begin with, you need to ensure that every time your addon displays a piece of text to the user, that piece of text ''can'' be localized. Consider the two pieces of code below:
{|
{| class="darktable"
| valign="top"| <pre>fontString:SetText("Hello World!")</pre>
|- valign="top" style="font-family:monospace;"
| valign="top"| <pre>local L = MyLocalizationTable;
|| fontString:SetText("Hello World!")
fontString:SetText(L["Hello World!"]);</pre>
| width="40px" |
|| local L = MyLocalizationTable;<br>fontString:SetText(L["Hello World!"]);
|}
|}
Code on the left could not be localized without editing the file containing it; while the code in the right wraps the output in a table lookup -- so if the value associated with the "Hello World!" key in MyLocalizationTable was altered, the text output would change. We can use a metatable to allow you to write localizable code without worrying about supplying a default localization:
Code on the left could not be localized without editing the file containing it; while the code in the right wraps the output in a table lookup -- so if the value associated with the "Hello World!" key in MyLocalizationTable was altered, the text output would change. We can use a metatable to allow you to write localizable code without worrying about supplying a default localization:
  local function defaultFunc(L, key)
  local function defaultFunc(L, key)
   -- If this function was called, we have no localization for this key.
   -- If this function was called, we have no localization for this key.
   -- We could complain loudly to allow localizers to see the error of their ways, but, for now, just return the key as its own localization. This allows you to avoid writing the default localization out explicitly.
   -- We could complain loudly to allow localizers to see the error of their ways,  
  -- but, for now, just return the key as its own localization. This allows you to  
  -- avoid writing the default localization out explicitly.
   return key;
   return key;
  end
  end
Line 137: Line 140:
== Tips and common pitfalls ==
== Tips and common pitfalls ==
* It is a generally good idea to separate localizable strings from your addon code if you intend to make your addon localizable -- concentrating localization in a few files makes it more approachable.
* It is a generally good idea to separate localizable strings from your addon code if you intend to make your addon localizable -- concentrating localization in a few files makes it more approachable.
* Avoid using names to identify things you can identify by ID instead (this would include items, spells, quests, NPCs, etc). IDs do not need to be localized, saving you work, and allowing your addon to work on a client of a different locale, even if only by using the original alnguage.
* Avoid using names to identify things you can identify by ID instead (this would include items, spells, quests, NPCs, etc). IDs do not need to be localized, saving you work, and allowing your addon to work on a client of a different locale, even if only by using the original language.
* Not everything must have a translation, and some things will break if translated. For instance, the names of the World of Warcraft API functions, XML elements, etc, do not need to be translated, since those names are hard-coded in either the client or FrameXML, and do not change with localizations.
* Not everything must have a translation, and some things will break if translated. For instance, the names of the World of Warcraft API functions, XML elements, etc, do not need to be translated, since those names are hard-coded in either the client or FrameXML, and do not change with localizations.


Line 143: Line 146:
* A complete [http://forums.wowace.com/showthread.php?t=15610 thread] where to download and upload updated v3.0.1+ WotLK GlobalStrings for all ten languages actually recognized (enUS enGB esES esMX deDE frFR ruRU zhCN koKR zhTW)  
* A complete [http://forums.wowace.com/showthread.php?t=15610 thread] where to download and upload updated v3.0.1+ WotLK GlobalStrings for all ten languages actually recognized (enUS enGB esES esMX deDE frFR ruRU zhCN koKR zhTW)  
* A github [http://github.com/tekkub/wow-globalstrings/tree/master repository] for storing community provided GlobalStrings.lua
* A github [http://github.com/tekkub/wow-globalstrings/tree/master repository] for storing community provided GlobalStrings.lua
* [http://wow.playhard.ru/Tools/ Tools] for help in russian localization
<references/>
Anonymous user