Thread Tools Display Modes
12-27-11, 05:58 PM   #1
Gregity
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 54
Localization for XML elements

I'm probably missing the obvious, but I am not coming up with a good method for localizing XML elements, such as the text on a button.

Supposing I have a button: <Button name="GLOBAL_VARIABLE_AS_A_STRING" inherits="UIPanelButtonTemplate" text="ANOTHER_GLOBAL_VARIABLE_AS_A_STRING" parent="SomeFrame">

This will create a global variable called GLOBAL_VARIABLE_AS_A_STRING. The text on the button will be either the value in quotes if there is no global variable with matching name or the value of the global variable if there is a matching name.

I understand that there is no way around the global variable connected to name. Is there a way to get the text used from the button to come from a table? I've tried several variations of variable naming (such as NameSpace.L.VarName hoping that it would look for Table NameSpace, sub-table L, variable VarName) and have had zero luck getting anything but a global variable to substitute.

What is the best practice method for avoiding littering the global namespace when using XML? Currently I'm using a prefix, but I'd rather put it all in a table if possible.

I am considering using the OnShow event to change out the text when the frame/button is shown. Is this a good or bad idea? Since this only needs to be done once per UI reload, is there a preferred way to limit it to updating the elements' text only one time (vs. per every show). Should I perhaps do this in the ADDON_LOADED event?

Or am I worrying over a small matter and just keep my Prefix idea?

-g
  Reply With Quote
12-27-11, 06:46 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
In all honesty, there's no need to localize a UI object's name since most if not all of the time, the only thing referencing the object is the addon itself.

As far as setting the text, you can have code in the OnLoad handler set it to the contents of a table element.
Note you need to have the table and element(s) defined in a Lua file before the XML file is loaded in the TOC.

Here is an example:
xml Code:
  1. <Button name="SomeButton" parent="SomeFrame" inherits="UIPanelButtonTemplate">
  2.     <Scripts>
  3.         <OnLoad>
  4.             self:SetText(NameSpace.L.VarName);
  5.         </OnLoad>
  6.     </Scripts>
  7. </Button>

If you want to add a bit of hierarchy to the names, the UI system allows use of $parent to stand in for the name of the object's parent. So if you decided to change the name of the button to say $parentButton, it'll create the button named SomeFrameButton.

If you don't plan on accessing the button outside of its own scripts or a script of one of its children, it's wise to not give it a name.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-27-11 at 06:55 PM.
  Reply With Quote
12-27-11, 08:51 PM   #3
Gregity
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 54
Thank you, that worked for me. The OnLoad in the XML is local to the XML file and only done one time per reload deal so no wasted effort either.

Alas, I do need to refer to the control to show and hide it so I'll need to keep the name.

I thought all Frame type things needed a name so I'm glad to find out I can dump the name if I don't need to refer to it.

Thanks again!
-g
  Reply With Quote
12-28-11, 08:56 AM   #4
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Though you can get rid of the XML altogether and use local variables as well...
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Localization for XML elements


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off