flex 国际化源代码

==============================================================

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添加刚刚的文件夹。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值