creates a new bundle for the fr_FR locale at run time. : ResourceBundle « Development « Flex






creates a new bundle for the fr_FR locale at run time.

           

<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".

This user guide is licensed for use under the terms of the Creative Commons Attribution 
Non-Commercial 3.0 License. 

This License allows users to copy, distribute, and transmit the user guide for noncommercial 
purposes only so long as 
  (1) proper attribution to Adobe is given as the owner of the user guide; and 
  (2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms. 
The best way to provide notice is to include the following link. 
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

-->


    <!-- l10n/CreateNewLocaleAndBundle.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> 
        import mx.resources.ResourceBundle; 
        import mx.controls.Alert; 
        import flash.display.*; 
        [Bindable] 
        private var locales:Array; 
        private function initApp():void { 
            locales = [ "es_ES","en_US" ]; 
            /* Initialize the ComboBox to the first locale in the locales Array. */ 
            localeComboBox.selectedIndex = locales.indexOf(resourceManager.localeChain[0]); 
            updateFlag(); 
        } 
        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 ]; 
            updateFlag(); 
        } 
        private var newRB:ResourceBundle; 
        private function updateFlag():void { 
            if (resourceManager.localeChain[0] == "fr_FR") { 
                /* Explicitly change the value of the flagImage source when the 
                locale is fr_FR because there was no class at compile time. */ 
                flagImage.source = "../assets/france.gif"; 
            } else { 
                /* Get the class from the resource bundle; this assumes that the classes 
                for all other locales were embedded in the resource bundles at 
                compile time. */ 
                flagImage.source = resourceManager.getClass('RegistrationForm', 'flag'); 
            } 
        } 
        private function createNewBundle():void { 
            locales.push("fr_FR"); 
            newRB = new ResourceBundle("fr_FR", "RegistrationForm"); 
            newRB.content["registration_title"] = "La Forme d'Enregistration"; 
            newRB.content["submit_button"] = "Soumettez La Forme"; 
            newRB.content["personname"] = "Nom"; 
            newRB.content["street_address"] = "Rue"; 
            newRB.content["city"] = "Ville"; 
            newRB.content["state"] = "Etat"; 
            newRB.content["zip"] = "Code postal"; 
            newRB.content["thanks"] = "Merci de l'enregistrement!"; 
            updateFlag(); 
            resourceManager.addResourceBundle(newRB); 
            resourceManager.update(); 
        } 
        private function resetApp():void { 
            resourceManager.removeResourceBundlesForLocale("fr_FR"); 
            initApp(); 
            resourceManager.update(); 
        } 
      </fx:Script>
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <fx:Metadata>
        [ResourceBundle("RegistrationForm")] 
    </fx:Metadata>
    <mx:Image id="flagImage" />
    <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()" />
    <mx:HRule width="100%" strokeWidth="1" />
    <s:HGroup>
        <s:Button id="b2" label="Add New Bundle" click="createNewBundle();" />
        <s:Button id="b3" label="Reset" click="resetApp();" />
    </s:HGroup>
</s:Application>

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Create Replacement Bundle
2.Print the keys and values for all resource bundles in all locales in the ResourceManager.