开发者

How to localize Flex/Actionscript "enums" to ensure bindability?

I have a simulated enum as follows:

public class Sport {
    public static const BASEBALL:Sport = new MyEnum("Baseball", "Baseball ...");
    public static const FOOTBALL:Sport = new MyEnum("Football", "Football ...");

    public var label:String;
    public var description:String;

    public function Sport(label:String, description:String):void {
        this.label = label;
        this.description = description;
    }
}

And buttons that bind to these enums as follows:

<mx:Button label="{Sport.BASEBALL.label}" toolTip="{Sport.BASEBALL.description}"/>

I now need to localize this enum, but haven't had much luck getting the binding to update along with everything else when I update the locale:

resourceManager.localeChain = [ localeComboBox.selectedItem ];

I've tried binding getters to the "change" event that supposedly gets thrown by R开发者_运维问答esourceManager, but that doesn't seem to work. Any ideas?


You could use

<mx:Button label="{resourceManager.getString('resourceBundleName', Sport.BASEBALL.label)}" toolTip="{resourceManager.getString('resourceBundleName', Sport.BASEBALL.description)}"/>

where Sport.BASEBALL.label and Sport.BASEBALL.description are the keys from your ResourceBundle.

You can also take a look at BabelFx which eliminates the need to insert all those ugly {resourceManager.getString(...)} statements. It uses runtime injection to localize your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜