【问题标题】:How to localize Flex/Actionscript "enums" to ensure bindability?如何本地化 Flex/Actionscript“枚举”以确保可绑定性?
【发布时间】:2010-10-23 00:52:35
【问题描述】:

我有一个模拟枚举如下:

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 抛出的“更改”事件,但这似乎不起作用。有什么想法吗?

【问题讨论】:

    标签: apache-flex actionscript flex3 localization resourcemanager


    【解决方案1】:

    你可以使用

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

    Sport.BASEBALL.label 和 Sport.BASEBALL.description 是 ResourceBundle 中的键。

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

    【讨论】:

    • 没错,这是一个选项。不过,感觉不是最理想的。我去看看 BabelFX。
    猜你喜欢
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 2021-04-19
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    相关资源
    最近更新 更多