2 Replies Latest reply on Dec 1, 2009 8:55 AM by acoquinar

    Bug with resourceManager and menuBar

    acoquinar

      I have a menuBar with two sub-items ("French", "English")

       

      Of course, each of them set localChain to  either "fr_FR" or "en_US" to change the language used for the entire UI.

       

      When i do this, everything gets translated alright expet the top menu items !  So in the code below, "Options" and "Help" stays in english after a switch to french. (The default language for my app at startup is english)

       

      To test this problem, i placed a button outside of the menu structure with action (click="localeChain=[fr_FR];") and it works fine !... Everything, including all the menu items gets translated !

       

      Any suggestion as to how i could get arround this bug ?

       

      Thanks !

       

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

       

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:components="components.*"  width="100%" height="100%" applicationComplete="init()"  backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#03006B, #03606B]"   layout="absolute">

       

       

          <mx:Script>

       

              <![CDATA[

       

       

       

                  import mx.events.MenuEvent;

       

                  import utilities.ResourceUtility;

       

                  import mx.resources.ResourceBundle;

       

                  import mx.controls.Alert;          

       

       

                  import mx.core.IFlexDisplayObject;

       

       

       


                   [Bindable]
                   public var frToggled:Boolean ;
                  
                   [Bindable]
                   public var enToggled:Boolean;


                  private function init():void
                  {
                     
                      ResourceUtility.setResources(resourceManager);

       

       

                      switch(resourceManager.localeChain.toString())

       

                      {

       

                          case "en_US":

       

                          enToggled=true;

       

                          frToggled=false;

       

                          break;

       

       

       

                          case "fr_FR":

       

                          enToggled=false;

       

                          frToggled=true;

       

                          break;

       

                      }      

       

       

       

       

       

                  private function menuClickHandler(event:MenuEvent):void

       

                  {

       

       

       

                      var menuItem:XML = event.item as XML;

       

       

       

                      switch (menuItem.@view.toString())

       

                      {

       

                          case "options":

       

       

       

                              break;

       

                          case "english":

       

                              resourceManager.localeChain = ['en_US'];

       

                              break;

       

                          case "french":

       

                              resourceManager.localeChain = ['fr_FR'];

       

                              break;

       

                          default:

       

                              break;

       

                      }

       

       

       

       

       

                  }            

       

       

       

       

       

              ]]>

       

          </mx:Script>

       

       

       

          <mx:MenuBar id="myMenuBar" labelField="@label" height="20" x="0" y="0" itemClick="menuClickHandler(event)"  fontWeight="bold" width="100%">

       

       

       

              <mx:XMLList>

       

       

       

                  <menuitem  label="{resourceManager.getString('myResources', 'TOOLS')}" view="tools">

       

                      <menuitem label="Options"/>

       

                      <menuitem label="{resourceManager.getString('myResources', 'LANGUAGE')}" view="language">

       

                          <menuitem  label="{resourceManager.getString('myResources', 'FRENCH')}"  view="french" type="radio" groupName="lang" toggled="{frToggled}"/>

       

                          <menuitem  label="{resourceManager.getString('myResources', 'ENGLISH')}" view="english" type="radio" groupName="lang"  toggled="{enToggled}"/>

       

                       </menuitem>

       

                  </menuitem>

       

                  <menuitem label="{resourceManager.getString('myResources', 'HELP')}" view="help">

       

                      <menuitem label="{resourceManager.getString('myResources', 'ABOUT_RS')}" view="about"/>

       

                  </menuitem>

       

              </mx:XMLList>  

      </mx:MenuBar>


             <mx:Button label="Switch to french" click="localeChain=[fr_FR];"/>

            
      </mx:Application>

       

       

      And here is the content of the ressource file (ResourceUtility.as)

       

      package utilities
      {
          import mx.resources.IResourceManager;
          import mx.resources.ResourceBundle;
         
          public class ResourceUtility
          {
              public static function setResources(
                  resourceManager:IResourceManager):void
              {
                  var myResources:ResourceBundle;
                 
                  myResources = new ResourceBundle("en_US", "myResources");
                  myResources.content["HELP"] = "Help";
                  myResources.content["ABOUT_RS"] = "About RS";
                  myResources.content["TOOLS"] = "Tools";
                  myResources.content["LANGUAGE"] = "Language";
                  myResources.content["FRENCH"] = "French";
                  myResources.content["ENGLISH"] = "English";
           
                 
                 
                 
                  resourceManager.addResourceBundle(
                      myResources);
                 
                  myResources = new ResourceBundle("fr_FR", "myResources");
                  myResources.content["HELP"] = "Aide";
                  myResources.content["ABOUT_RS"] = "À Propos de RS";
                  myResources.content["TOOLS"] = "Outils";
                  myResources.content["LANGUAGE"] = "Langue";
                  myResources.content["FRENCH"] = "Français";
                  myResources.content["ENGLISH"] = "Anglais";

       

                  resourceManager.addResourceBundle(
                      myResources);
                     
                  resourceManager.update();           
              }

       

          }
      }

        • 1. Re: Bug with resourceManager and menuBar
          paul.williams Level 4

          There does appear to be a bug / feature / limitation with the MenuBar. If the dataProvider changes when a menu is open the change is ignored and the menu is not updated; this avoids sub-menu controls from being orphaned. It is fine for the sub-menus because they will be updated the next time they are displayed, but it means the top-level items become stale.

           

          A workaround would be to change your locale once the menu has closed. A callLater worked for me:

           

          itemClick="callLater( menuClickHandler, [event] )"

           

          A possible alternative would be to listen for the menuHide event and then update the locale.

          • 2. Re: Bug with resourceManager and menuBar
            acoquinar Level 1

            Does the trick !!!!

             

            I didn't know about this callLater thing...

             

            Thanks man !