Adobe Flex 3 Help

Introduction to localization

Localization is the process of including assets to support multiple locales. A locale is the combination of a language and a country code; for example, en_US refers to the English language as spoken in the United States, and fr_FR refers to the French language as spoken in France. To localize an application, you would provide two sets of assets, one for the en_US locale and one for the fr_FR locale.

Locales can share languages. For example, en_US and en_GB (Great Britain) are different locales and therefore use different sets of assets. In this case, both locales use the English language, but the country code indicates that they are different locales, and might therefor use different assets. For example, an application in the en_US locale might spell the word "color", whereas the word would be "colour" in the en_GB locale. Also, units of currency would be represented in dollars or pounds, depending on the locale, and the format of dates and times might also be different.

Localization goes beyond just translating Strings used in your application. It can also include any type of asset such as audio files, images, and videos. Because the meanings of colors and images can vary based on the culture, you can change the styles used by your application, in addition to the language used, based on the locale.

Localizing Flex applications

To localize an application, you first create properties files that define the localized assets. You must understand the properties file syntax and know what types of resources can be added to resource bundles. For more information, see Creating resources.

You then compile these properties files into the application as resource bundles, or create resource modules from the properties files and load them at run time.

Flex lets you change locales on the fly; if you compile more than one resource bundle into an application, you can toggle the resource bundle based on the locale. In addition, if you compile resource modules, you can load and unload the SWF files at run time based on the locale. You can even create new resource bundles programmatically.

How you load your resource bundles depends on how many locales your application supports. If your application supports just one or two locales, then you typically compile all the resources into the application. For more information, see Using resources.

If your application supports many locales, you will likely want to load the appropriate resources at run time rather than compile all supported resources into the application at compile time. To do this, you compile your resource bundles into resource modules. For more information, see Using resource modules.

Choosing a locale

To determine which locale your users will want to experience your application in, you can use one of the following methods:

  • User prompt -- You can start the application in some default locale, and then ask the user to choose their preferred locale.
  • Capabilities.language -- The Capabilities.language property in ActionScript provides the language code for Adobe® Flash® Player and Adobe AIR™. On English systems, this property returns only the language code, not the country code. This property returns the user interface language, which refers to the language used for all menus, dialog boxes, error messages, and help files in Flash Player and AIR.
  • Accept-Language header -- When a browser makes an HTTP request, it send a list of languages to the server in the Accept-Language header. You can parse this header in your HTML wrapper and pass it as a flashVars variable into your Flex application. If you use URLLoader to load an application, you will not have access to this header.
  • Browser and OS language settings -- You can access the browser's or operating system's language settings in the HTML wrapper by using JavaScript. You can then pass the values as flashVars variables to your application. You can also use the ExternalInterface API to access the values from within your Flex application. The language is typically accessible via the Navigator object's language property. Depending on the browser, you also access the userLanguage or systemLanguage properties. For more information on using the ExternalInterface API, see Using the ExternalInterface API to access JavaScript from Flex.