load locale at runtime using resource modules

I was asked to find a way for separating our localization resources out of the application swf, so that different locales can be loaded at runtime.
Pretty quickly I found the "Using resource modules" help subject, which explains how to create, compile and load resource modules,  which are SWF files, separated from your application SWF, that contain resources bundles for a single locale.
While trying to set up a demo application (didn't found one) using the instructions in the help files, I bumped into several issues which I will explain here in hopes that it will save you the time, and added the sample app as well.
1.       Running MXMLC – In case you're not familiar with executing the compiler, you should note that you can either use it as mentioned in the article:
mxmlc -locale= -resource-bundle-list=myresources.txt MyApp.mxml
(supply full path to MyApp.mxml, or run the compiler from the folder of your app. Either way, you better add the path to the mxmlc to your path environment variable).
Alternatively you can add the following to the Flex builder additional compiler options :
-locale= -resource-bundle-list=myresources.txt 
In either case, you'll probably want to create this file in a specific place rather than under the compiler folder, so you should use something like:
.. -resource-bundle-list=C:/resources/myresources.txt 
Later, when compiling the resource module, you should note that the -source-path=locale/{locale} argument assumes that you execute the compiler from your project's folder, so your command line will look something like:
C:\Flex\Projects\localizationModules>mxmlc -locale=es_ES -source-path=src/locale/{locale} -include-resource-bundles=RegistrationForm,collections,containers,controls,core,  effects,skins,styles -output es_ES_ResourceModule.swf 
Where -locale is the name of the folder containing different locales. 
2.       Supported locales- When first trying to compile for the es_ES locale,  I got the following error:
C:\Program Files\Adobe\Flex Builder 3\sdks\3.4\frameworks\flex-config.xml(75): Error: unable to open 'locale/es_ES'
The reason for this is that the es_ES framework locale (which includes resources for framework classes such as buttons etc.) did not exist on my machine. Only the en_UN is provided by default (I found the ja_JP as well). You can find all the explanations under "Adding new locales".
In short, You have to add the framework resource locale for this problem to go away.
If you only want to run a demo to see this working, and don't want to be bothered with adding the locale, just look into your installed locales (something like C:\Program Files\Adobe\Flex Builder 3\sdks\3.4\frameworks\locale). In case you find another one on top of en_UN (i.e ja_JP), you can create a resource module from it, and simply change the sample code to use this locale instead:
private var locales:Array = [ "en_US","ja_JP" ]; 
The sample app included here uses this. Of course, the actual resources you see in the labels remain Spanish :) This is just for demo. 
3.       You should take care of copying the resource module's swf's to your output folder so they can be loaded.
Hope this will save you the time for making this work.
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com