0 Replies Latest reply on May 12, 2013 11:38 PM by Jack Zhang

    How to provide localization for MenuBar component

    Jack Zhang Level 1

      I wish to know that resource bundle method of MenuBar component, below is my test code:

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                           xmlns:s="library://ns.adobe.com/flex/spark"

                                                           xmlns:mx="library://ns.adobe.com/flex/mx"

                                                           width="600" height="450"

                                                           creationComplete="creationCompleteHandler(event)">

       

                <!--fx:Metadata>

                          [ResourceBundle("RegistrationForm")]

                </fx:Metadata-->

                <fx:Script>

                          <![CDATA[

                                    import mx.collections.ArrayCollection;

                                    import mx.controls.Alert;

                                    import mx.events.FlexEvent;

                                    import mx.resources.ResourceBundle;

       

                                    [ResourceBundle("RegistrationForm")]

       

                                    [Bindable]

                                    private var languageArrayCollection:ArrayCollection = new ArrayCollection(

                                              [          {item:"en_US", name:"English"},

                                                        {item:"zh_CN", name:"中文"}

                                              ]               

                                    );

       

                                    private function creationCompleteHandler(e:Event):void

                                    {

                                              var item:String = "en_US";

                                              resourceManager.localeChain = [item];

       

                                              var language:String = resourceManager.localeChain[0];

                                              trace("language: " + language);

                                              for(var i:uint; i < languageArrayCollection.length; i++)

                                              {

                                                        if(language == languageArrayCollection[i].item)

                                                        {

                                                                  localeComboBox.selectedIndex = i;

                                                                  break;

                                                        }

                                              }

                                    }

                                    private function registrationComplete():void

                                    {

                                              Alert.show(resourceManager.getString('RegistrationForm', 'thanks'));

                                    } 

                                    private function comboChangeHandler():void

                                    {

                                              var language:String = localeComboBox.selectedItem.item as String;

                                              resourceManager.localeChain = [language];

       

                                              trace("change language: " + resourceManager.localeChain[0]);

                                    }

       

                          ]]>

                </fx:Script>

                <s:VGroup top="10" bottom="10" left="10" right="10">

                          <mx:MenuBar labelField="@label">

                                    <mx:dataProvider>

                                              <fx:XMLList>

                                                        <menuitem label="MenuItem A">

                                                                  <menuitem label = "SubMenuItem A-1"/>

                                                                  <menuitem label = "SubMenuItem A-2"/>

                                                                  <menuitem label = "resourceManager.getString('RegistrationForm','menu')"/>

                                                        </menuitem>

                                                        <menuitem label="MenuItem B">

                                                                  <menuitem label="SubMenuItem B-1"/>

                                                                  <menuitem label="SubMenuItem B-2"/>

                                                        </menuitem>

                                              </fx:XMLList>

                                    </mx:dataProvider>

                          </mx:MenuBar>

       

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

                          <s: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>

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

                          </s:Form>

                          <s:Button label="{resourceManager.getString('RegistrationForm','submit_button')}" click="registrationComplete()"/>

                </s:VGroup>

      </s:WindowedApplication>