如何本地化 Flex/Actionscript“枚举”确保可绑定性?

发布于 2024-09-28 20:14:16 字数 801 浏览 2 评论 0原文

我有一个模拟枚举,如下所示:

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

我'我尝试将 getters 绑定到应该由 ResourceManager 抛出的“change”事件,但这似乎不起作用。有什么想法吗?

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 ResourceManager, but that doesn't seem to work. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩扇题诗 2024-10-05 20:14:16

您可以使用

<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(. ..)} 语句。它使用运行时注入来本地化您的应用程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文