With Flex 3 comes the ability to do runtime localization. Compared to Flex 2 where you actually had to recompile your application for each locale, you can now have one version of your application that contains different resource bundles.
Today I implemented this in one of the applications we are working on and ran into some issues. Here is how I got it to work in a nutshell. (Note: for a full instruction on implementing localization in Flex 3, I recommend the article Flex 3:Feature Introductions: Runtime Localization by Gordon Smith.)
- create a folder in your project to store your resource bundles (e.g. "locale")
- create a subfolder for each locale you want to implement (e.g. "locale\nl_BE" and "locale\fr_BE")
- in the locale subfolder, create a resources.properties file and save it as UTF-8
- enter the resources in the form of "key=value", like Ant property files
- update the compiler settings: -locale=nl_BE,fr_BE -source-path=locale/{locale}
You now also need to create localized framework resources. To do this, take the following steps:
- open a command line (run as administrator in Vista!)
- go to the "bin" folder in your Flex SDK installation folder
- run the copylocale.exe tool for each locale, this will copy the localized framework files from one locale to another (copylocale en_US nl_BE)
- check FLEX_HOME\frameworks\locale to see if the folder for your new locale has been created
- if you get an error "could not find resource bundle charts", search for a file called charts_rb.swc and copy it to the new locale folder in FLEX_HOME\frameworks\locale
A simple example of asking for a localized string:
-
// tell the compiler what resourcebundle to use
-
<mx:Metadata>
-
[ResourceBundle("resources")]
-
</mx:Metadata>
-
-
// if you are in a subclass of UIComponent
-
var myString:String = resourceManager.getString("resources", "myKey");
-
-
// ...or if you are not in a subclass of UIComponent
-
var myString:String = ResourceManager.getInstance().getString("resources", "myKey");
You can put these calls in a binding expression and switch your locale at runtime by setting the localeChain property on the resourceManager:
-
resourceManager.localeChain = ["nl_BE"];
That's about it. Have fun!
Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
Christophe Herreman is a software developer living in Belgium. He's working on Flex based e-learning solutions at
Recent Comments