In MXML components you can simply use databinding expressions like

 

    <Button label="{resourceManager.getString(...)}"/>

 

but in AS3 components you need to override resourcesChanged() -- which gets 
called when the ResourceManager's localeChain changes -- and reset the label.

 

- Gordon

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Matias 
Nicolas Sommi
Sent: Sunday, June 22, 2008 9:43 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Automatic programatically controls binding (i18n)

 

Hello, recently i could make my app in two langs, but i have one
problem, i wrote a class "I18n" with one static method called
"getLanguageSelector" who gives me a Label and a ComboBox in a
container. In the combobox the user can change his language. When the
user changes his language, the app changes the localchain property of
resourceManager.
My problem is, all the controls in the mxml app changes his labels
automatically, but the labels, like the label i return in the method
"getLanguageSelector" does not change.
I tried to make the label [Bindable] but it does not work.
If you have some ideas, please tell me. Thanks.
The I18n Class looks like this:

public class I18n
{
public static const locales:Array = ["en_US", "es_ES"];

[Bindable]
private static var _container:HBox;

public static function getLanguageSelector():DisplayObject
{
if(_container == null)
{
_container = new HBox();

var _combo:ComboBox = new ComboBox();
var _label:Label = new Label();
//display items
var languages:Array = ["English", "Espanol"];

_label.name = "lblLang";
_combo.name = "cmbLang";
_combo.dataProvider = languages;

//select default language
_combo.selectedIndex = 0;
ResourceManager.getInstance().localeChain = [locales[_combo.selectedIndex]];

_label.text = ResourceManager.getInstance().getString('general',
'change_language');
_label.includeInLayout = true;

_combo.addEventListener(Event.CHANGE, I18n.onSelectionChange);
_container.addChild(_label);
_container.addChild(_combo);
}
return _container;
}

public static function onSelectionChange(e:Event):void
{
ResourceManager.getInstance().localeChain =
[locales[(_container.getChildByName("cmbLang") as
ComboBox).selectedIndex]];
}

}

Best Regards.
-- 
Matías Nicolás Sommi

 

Reply via email to