Flex locale
ResourceBundle的使用
新建文件夾(Locale)保存Locale資源
建子文件夾(en_US, cht_HK)用於區分Locale
在eu_US, cht_HK中分別添加資源配置文件 (資源名稱.properties)
項目屬性中設置Source Path,Add Folder "Locale/{locale}", 其中{locale}將被編譯參數 -locale 自動替換
需要用locale的as 或 mxml中增加引用對象
[ResourceBundle("資源名稱")]
private static var rb:ResourceBundle;
<<--code AlertTest.mxml >>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.resources.ResourceBundle;
import mx.controls.Alert;
[ResourceBundle("AlertMessage")]
private static var rb:ResourceBundle;
private function alertMessage():void
{
Alert.show(rb.getString('AlertMessage'));
}
]]>
</mx:Script>
<mx:Button label="@Resource(key='AlertButtonName', bundle='AlertMessage')" click="alertMessage()"/>
</mx:Application>
<< - code locale/en_US/AlertMessage >>
AlertMessage=The alert message in English
AlertButtonName=click me
<< - code locale/cht_HK/AlertMessage.properties 注意,中文應使用UTF-8編碼
file-properties-info-Text file encoding >>
AlertMessage=繁體中文提示信息
AlertButtonName=點我
然後在編譯時設置Locale 右點項目-屬性-Complier-Additional Complier Arguments "-locale cht_HK"