Monday, July 23, 2007

About localized Flex applications

Using Flex, you can write localized applications and access localized components. Flex supports static inclusion of localized resources, but not dynamic retrieval of resources at run time.

Subtopics
About resource bundles and properties files
The localization workflow
About resource bundles and properties files
Resource bundles, or properties files, map keys and values by using simple "key=value" syntax. This is similar to Java properties files; the primary difference from the Java properties format is that you store the Flex properties files as UTF-8 if they contain non-ASCII characters.

The Flex compilers find the properties files the same way that the compilers find other source files. You put the properties files in directories that the compiler searches.

You can access the values in the resource bundles in the following ways:

MXML Use the @Resource directive inside your MXML tags.

ActionScript Use the [ResourceBundle] metadata tag to create an instance of the ResourceBundle class in ActionScript.

In some cases, you must also specify the name of the resource bundle to access the data inside it. The resource bundle in your code uses the same name as the properties file.

The localization workflow
To localize an application, you use the ResourceBundle API. You do this by adding [ResourceBundle] metadata tags in ActionScript or @Resource calls in MXML, creating localized properties files and localization classes and put them into a locale directory, and using the mxmlc compiler to compile the main application.

Optionally, you can package libraries of localized properties files and ActionScript classes in a SWC file that you create with the compc compiler. However, a resource bundle SWC file is necessary only when you are creating a library rather than an application.

No comments: