2

我有一个模拟枚举如下:

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;
    }
}

绑定到这些枚举的按钮如下:

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

我现在需要本地化这个枚举,但是当我更新语言环境时,我没有太多运气让绑定与其他所有内容一起更新:

resourceManager.localeChain = [ localeComboBox.selectedItem ];

我尝试将 getter 绑定到据称由 ResourceManager 抛出的“更改”事件,但这似乎不起作用。有任何想法吗?

4

1 回答 1

3

你可以使用

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

哪里Sport.BASEBALL.labelSport.BASEBALL.description是您的 ResourceBundle 中的键。

您还可以查看BabelFx,它消除了插入所有这些丑陋{resourceManager.getString(...)}语句的需要。它使用运行时注入来本地化您的应用程序。

于 2010-10-23T09:08:13.260 回答