==============================================================
FlexInternationalDemo.mxml
-------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.resources.ResourceManager;
import com.ResourceUtil;
[Bindable]
private var ru:ResourceUtil = ResourceUtil.getInstance();
private function changeLanguage(language:String):void {
ru.language = language;
}
]]>
</mx:Script>
<mx:Label id="label1" x="10" y="10" text="{ru.getString('flex_label1')}" />
<mx:Label id="label2" x="10" y="38" text="{ru.getString('flex_label2')}"/>
<mx:Label id="label3" x="10" y="58" text="{ru.getSubstitute('flex_message','Anant', 'Nick')}" />
<mx:Button x="10" y="88" label="Chinese" click="changeLanguage('zh_CN')"/>
<mx:Button x="88" y="88" label="English" click="changeLanguage('en_US')"/>
</mx:Application>
=====================================================
ResourceUtil.as
-------------------------------------------------------------
package com
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import mx.resources.ResourceManager;
import mx.utils.StringUtil;
import mx.resources.ResourceBundle;
public class ResourceUtil extends EventDispatcher
{
private static var _instance : ResourceUtil;
private var _language : String;
[ResourceBundle("en_US")]
private var lang_en:ResourceBundle;
[ResourceBundle("zh_CN")]
private var lang_zh:ResourceBundle;
public static function getInstance() : ResourceUtil {
if(_instance == null) {
_instance = new ResourceUtil();
}
return _instance;
}
[Bindable(event="languageChange")]
public function getString(key:String):String {
return ResourceManager.getInstance().getString(_language,key);//localResources.getString(key);
}
[Bindable(event="languageChange")]
public function ResourceUtil(){
this.language = "zh_CN";
}
public function set language(language : String):void {
this._language = language;
dispatchEvent(new Event("languageChange"));
}
public function getSubstitute(key : String, ... rest):String
{
return StringUtil.substitute(ResourceManager.getInstance().getString(_language,key),rest);
}
}
}
====================================
在src的同级目录添加property目录,在目录下添加
en_US.properties
message.demo1=Hello
flex_label1=hello gays
flex_label2=hi
flex_message={0}00{1}11.
zh_CN.properties
message.demo1=你好
flex_label1=欢迎大家
flex_label2=各位好啊
flex_message={0}赶在{1}之前到的.
在工程的Flex BuildPath的Source Path添加刚刚的文件夹。