→Making an addon localizable
m (I hate having to scroll sideways, and I'm on a 1366 width screen.) |
|||
| Line 46: | Line 46: | ||
=== 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"| | |- valign="top" style="font-family:monospace;" | ||
| | || fontString:SetText("Hello World!") | ||
fontString:SetText(L["Hello World!"]); | | 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: | ||