2 Replies Latest reply on Jul 2, 2007 1:36 PM by GordonSmith

    Flex 3 Runtime Localization Thread 2

    cheftimo Level 2
      This is a newbie question.

      In the simple sample application, the labels in the ‘localeComboBox’ read “en_US” and “fr_FR”. That is not really human-readable from a site visitor’s point of view.

      I tried changing the ‘locales’ Array to [“English” , “Français”], and, of course, that doesn’t work, because the localeChain is also set from the ‘ComboBox.selectedItem’. I imagine you have to have ‘label’ and ‘data’ properties for the ComboBox,

      Could someone please provide some hint or URL where I can look this up?

      Carlos
        • 1. Re: Flex 3 Runtime Localization Thread 2
          cheftimo Level 2
          I am re-posting, because I was not completely clear when I started this thread.

          The localeChain and the ComboBox works off
          Private var locales:Array [“en_US”,”es_CO”,”fr_FR”]

          I had already fixed the label issue like this:
          I replaced

          private function localeComboBox_changeHandver(event:Event):void{
          // set the localeChain to one of the one-element Arrays en_US, fr_FR or es_CO
          resourceManager.localeChain = [localeComboBox.selectedItem];
          }
          <mx:ComboBox id="localeComboBox" dataProvider="{locales}"
          initialize="localeComboBox_initializeHandler(event)"
          change="localeComboBox_changeHandler(event)"/>

          with

          private function localeComboBox_changeHandler(event:Event):void{
          // set the localeChain to one of the one-element Arrays en_US, fr_FR or es_CO
          resourceManager.localeChain = [localeComboBox.selectedItem.lang];
          }
          <mx:ComboBox id="localeComboBox"
          initialize="localeComboBox_initializeHandler(event)"
          change="localeComboBox_changeHandler(event)">
          <mx:dataProvider>
          <mx:Object label="English" lang="en_US"/>
          <mx:Object label="Español" lang="es_CO"/>
          <mx:Object label="Français" lang="fr_FR"/>
          </mx:dataProvider>
          </mx:ComboBox>

          Of course, that works, but it’s not what I am after. This is fine if you have two or three locales, not so good if you have fifteen or twenty.

          What I am after is just creating the array ‘locales’; then, if you add or replace an element in that array, make the ComboBox ‘lang’ change from that array, without having to re-type the locales in two places.

          I hope this is clear.

          Carlos
          • 2. Re: Flex 3 Runtime Localization Thread 2
            GordonSmith Level 4
            I would define

            private var locales:Array =
            [
            { label: "English", data: "en_US" },
            { label: "Francais", data: "fr_FR" }
            ];

            and use this as the ComboBox's dataProvider. The logic in localeComboBox_initializeHandler() to set the ComboBox's selectedIndex would need to be slightly more complicated... instead of simply using indexOf(), you'll have to search the 'locales' array for an item whose 'data' property is the locale.