Tutorial: Internationalization in ELIPS

Resource bundle is a great way to separate locale-related content from the rest of your code. Working with resource bundle in ELIPS is relatively easy as it is based on the original Flex 3.5 mechanism save few tricks you should know about.

Follow this tutorial in order to internationalize your app. You can also refer to the i18n sample application.


Setting up your project

  1. Create a "locale" directory in your project root (Mandatory).

  2. Create a subfolder for each locale you wish to use. The subfolder name should be normalized as follows: eng_US (i.e. [language on 3 chars]_[COUNTRY ON 2 CHARS]).

  3. IMPORTANT NOTE REGARDING LOCALES

    In ELIPS, the locale code is on 3_2 (ex: eng_US) characters instead of the 2_2 (ex: en_US) as used in Flex.


  4. Create in each subfolder a "[Bundle].properties" file that will contain the strings to be localized. This properties file is a simple text file containing key/value pairs.


  5. Edit your project properties to add in the "Flex Compiler" options, the argument: "-locale=" followed by the locale codes separated with comas.


  6. Update the "Flex Build Path" to include the "locale\{locale}" path into the app.


Editing the properties files

The properties file is what the compiler uses to make the resource bundle. It is made up of simple key/value pairs, key being used for reference in your code and value being the translated string for the locale.

  1. For each locale, fill in the corresponding properties file with the same keys and translated value.

    L_first=English text
    L_second=This is some other text we want to localize


NOTE

Make sure to save your properties file using the UTF8 encoding if your are dealing with languages requiring such encoding like French for instance. In flex builder, go to "File"->"Properties" then set the "Text file encoding" to UTF8 then "apply". You may need to clean your project for the change to be taken into account.


Using the Resource Bundles

  1. In order for flex to know which resource bundles you plan on using in the app, you need to explicitly tell it using metadata tags.
    In mxml it looks like:
    <mx:Metadata>
         [ResourceBundle("myBundle")]
    </mx:Metadata>

    and in actionscript it looks like:
    [ResourceBundle("myBundle")]

  2. To set the locale, use the following method:
    resourceManager.localeChain=['eng_US']

  3. To access to the localized string, use the following method:
    resourceManager.getString('myBundle', 'L_first')

 

Be sure to check the i18n sample application for an example.