Tuesday, February 12, 2008

Localising And Resource Bundles in Flex 3.0

Handling resource bundles in flex 3.0 has improved a lot from the previous version.

you just need to add loacale{locale} folder in the source path of the application and have to keep the en_US or ja_JP (which ever language refrence you want to add)

then you will have to make sample.properties file in each of the language refrence folder

in properties file you will have to add
hello=Hello World

the properties which you need to access from the application(here i used hello property)

in the application we will use


we can make the mapping of the resource bundle dynamic with the following code.

add the code in the script of the application





[ResourceBundle("sample")]


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

private function localeComboBox_initializeHandler(event:Event):void
{
localeComboBox.selectedIndex =
locales.indexOf(resourceManager.localeChain[0]);
}

private function localeComboBox_changeHandler(event:Event):void
{
// Set the localeChain to either the one-element Array
// [ "en_US" ] or the one-element Array [ "fr_FR" ].
resourceManager.localeChain = [ localeComboBox.selectedItem ];
}


initialize="localeComboBox_initializeHandler(event)"
change="localeComboBox_changeHandler(event)"/>




Change the -locale option to be

-locale=en_US,fr_FR

No comments:

About Me