Monday, January 9, 2012

L10n in Flex Quick Guide

Recently I was looking into localization of my Flex project, not to support multiple language, but to support different server environment setup.

So I came up with two options:
  1. Using l10n property file:
    1.  Create a locale directory right under the project.
    2. Add a sub directory under locale named with the locale you want to add.
    3. Add the property file under the sub directory (Note this is different than the Java i18n setup which you just create property file in the pattern <Resource Name>_<locale>.properties)
    4. Repeat 2 and 3 if you have more locales to add.
    5. Go to Project Properties and then Flex Compiler, in the Additional compiler argument section add "-locale <locale list seperated by comma> -source-path=locale/{locale} -allow-source-path-overlap=true"
    6. In mxml file add [ResourceBundle("<Resource File Name>")] to metadata.
    7. Wherever you need a resource, use resourceManager.getString('<Resource File Name>', '<Resource Key>').
  2. Passing environment variables as FlashVars:
    1. Add flashvars as parameter in object in jsp file
    2.  In mxml, using FlexGlobals.topLevelApplication.parameters.<parameter key> to get the passed in value
 

Option 2 is obviously easier to setup.  We don't need to add additional property files but reference existing resource setup in Java project.

No comments: