flex4国际化

 

 

国际化变得如此简单

<?xml version="1.0"?>
<!-- l10n/CreateReplacementBundle.mxml -->
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    creationComplete="initApp()"> 

    <fx:Script><![CDATA[
        import mx.resources.ResourceBundle;
        import mx.controls.Alert;

        [Bindable]
        private var locales:Array = [ "es_ES","en_US" ];

        private function initApp():void {
            /* Initialize the ComboBox to the first locale in the locales Array. */
            localeComboBox.selectedIndex = locales.indexOf(resourceManager.localeChain[0]);
        }

        private function registrationComplete():void {
            Alert.show(resourceManager.getString('RegistrationForm', 'thanks'));
        }  

        private function comboChangeHandler():void {
            /* Set the localeChain to either the one-element Array
               [ "en_US" ] or the one-element Array [ "es_ES" ]. */
            resourceManager.localeChain = [ localeComboBox.selectedItem ];            
        }
        
        private function createReplacementBundle():void {
            var newRB:ResourceBundle = new ResourceBundle("en_US", "RegistrationForm");
            
            newRB.content["registration_title"] = "Registration Form";
            newRB.content["submit_button"] = "Submit This Form";
            newRB.content["personname"] = "Enter Your Name Here:";
            newRB.content["street_address"] = "Enter Your Street Address Here:";
            newRB.content["city"] = "Enter Your City Here:";
            newRB.content["state"] = "Enter Your State Here:";
            newRB.content["zip"] = "Enter Your ZIP Code Here:";
            
            resourceManager.addResourceBundle(newRB);            
            resourceManager.update();            
        }
    ]]></fx:Script>

    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout>

    <fx:Metadata>
        [ResourceBundle("RegistrationForm")]
    </fx:Metadata> 

    <mx:Image source="{resourceManager.getClass('RegistrationForm', 'flag')}"/>

    <mx:ComboBox id="localeComboBox" 
        dataProvider="{locales}"
        change="comboChangeHandler()"/>

    <mx:Form>
        <mx:FormItem label="{resourceManager.getString('RegistrationForm','personname')}">
            <mx:TextInput/>
        </mx:FormItem>
        <mx:FormItem label="{resourceManager.getString('RegistrationForm','street_address')}">
            <mx:TextInput/>
        </mx:FormItem>
        <mx:FormItem label="{resourceManager.getString('RegistrationForm','city')}">
            <mx:TextInput/>
        </mx:FormItem>
        <mx:FormItem label="{resourceManager.getString('RegistrationForm','state')}">
            <mx:TextInput/>
        </mx:FormItem>
        <mx:FormItem label="{resourceManager.getString('RegistrationForm','zip')}">
            <mx:TextInput/>
        </mx:FormItem>
    </mx:Form>
    
    <s:Button id="b1" 
        label="{resourceManager.getString('RegistrationForm','submit_button')}" 
        click="registrationComplete()"/>
    
    <s:Button id="b2" 
        label="Change Bundle" 
        click="createReplacementBundle()"/>
    
</s:Application>

 

更多参考:

官网:http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f2c.html

ResourceManager:http://docs.huihoo.com/flex/4/mx/resources/ResourceManager.html

ResourceBundle:http://docs.huihoo.com/flex/4/mx/resources/ResourceBundle.html

http://www.cnblogs.com/zhych/archive/2009/11/02/1594268.html

http://developer.51cto.com/art/201007/214627.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值