Adobe Flex 3: Load Framework Localization Resources at Runtime using XML
In a previous post, I wrote an article describing how to perform localization in Adobe Flex at runtime by loading resource from a XML file.
-> Adobe Flex 3: Load localization resources at runtime using XML
Several comments came in discussing issues where default Flex framework resources would display “NULL” instead of “Ok”, “Yes”, “No”, etc.
This article is intended to address those NULL string issues and demonstrate how to provide localized Flex framework resources in the XML resource file.
The Problem
The default Adobe Flex strings for UI controls and Alert dialogs, etc are located in framework resource bundles”.
Unfortunately Adobe does not ship default country neutral resource locales like “en” , they only include US English and Japanese specific locales like “en_US” and “ja_JP”.
The Hack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <?xml version="1.0"?> <locales> <locale id='en' label='English'> <localeChain> <item>en</item> <item>en_US</item> </localeChain> </locale> <locale id='en_US' label='English (United States)'> <localeChain> <item>en_US</item> <item>en</item> </localeChain> </locale> <locale id='en_GB' label='English (Great Britain)'> <localeChain> <item>en_GB</item> <item>en</item> <item>en_US</item> </localeChain> </locale> <locale id='es' label='Spanish'> <localeChain> <item>es</item> <item>en</item> <item>en_US</item> </localeChain> </locale> <locale id='es_MX' label='Spanish (Mexico)'> <localeChain> <item>es_MX</item> <item>es</item> <item>en</item> <item>en_US</item> </localeChain> </locale> <locale id='fr' label='French'> <localeChain> <item>fr</item> <item>en</item> <item>en_US</item> </localeChain> </locale> <locale id='fr_CA' label='French (Canada)'> <localeChain> <item>fr_CA</item> <item>fr</item> <item>en</item> <item>en_US</item> </localeChain> </locale> </locales> |
The Solution
When adding other locales, you must also include the framework resources for that locale. The en_US locale is already provided. For all other locales, you must create the framework resources. To create a locale’s framework resources, use the copylocale utility in the /sdk/bin directory. For Flex Builder, the copylocale utility is located in flex_builder_install/sdks/3.0.0/bin. You can only execute this utility from the command line.
See this article for Adobe’s notes:
Now if you would prefer to load these framework resources using the same XML resource file as demonstrated in the previous article, its pretty simple to do. The existing “XmlResourceLoader” class in the sample project already supports the handling of multiple resource bundles from each loaded XML resource file. The goal here is to additionally define the framework resource bundle resource strings in each language/locale specific resource XML file. If you look at the existing sample source code, it lists a single resource bundle in the XML file, but the code does support multiple bundles. For example, you can additionally define the “controls” (framework) resource bundle and include all the resources strings needed in the “controls” bundle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?xml version="1.0"?> <!-- ************************* SPANISH RESOURCES ************************* --> <resources> <resourceBundle name="myResources"> <resource name="myResourceOrigin" value="Spanish Lanugage; Culture Neutral"/> <resource name="myLocalizedLabel" value="Hola Mundo!" /> <resource name="myLocalizedButton" value="Color"/> <resource name="myResourceFlagImage" value="assets/images/spain-flag.png"/> </resourceBundle> <resourceBundle name="controls"> <resource name="okLabel" value="Bueno"/> <resource name="yesLabel" value="Si" /> <resource name="noLabel" value="No"/> <resource name="cancelLabel" value="Cancelar"/> </resourceBundle> </resources> |
You would of course need to define resources for each of the framework resource bundles for each of the language/locales that you intend to support. Too bad Adobe does not provide more localized framework resource bundles in the SDK.

