Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Building multilingual Flex applications on Adobe AIR

by Christian Cantrell

Christian Cantrell
  • blogs.adobe.com/cantrell

Created

18 June 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR application Flex localization

Requirements

Prerequisite knowledge

This article assumes that you are familiar with Adobe AIR and Flex.

User level

All

Required products

  • Flex Builder (Download trial)
  • Adobe AIR

Sample files

  • Apprise_source.zip (319 KB)
  • Apprise.air (857 KB)

Adobe AIR 1.1 adds an important new capability to help us reach our goal of getting the AIR runtime on as many computers as possible: localization. This article describes the new localization functionality in AIR 1.1, discusses our localization framework support, and outlines the process I went through to localize Apprise, a simple but powerful feed aggregator written for AIR (see Figure 1).

Note: Apprise is an open source project; you can find the latest code at Google Code.

Apprise application
Figure 1. Apprise is a simple but powerful RSS feed aggregator.

Understanding localization support in Adobe AIR 1.1

Adding localization to a platform is tricky because it's not just a single feature; it's actually a bunch of features that allow both the AIR runtime and AIR applications to be completely at home on non-English systems.

The list of components that make up the AIR 1.1 localization support include:

  • Improved language rendering: The AIR 1.1 runtime should be able to render characters in just about any written language in both SWF and HTML content (including SWF in HTML).
  • Runtime localization: Runtime dialog boxes (such as the runtime installer and application installer), application dialog boxes (such as the file browser, JavaScript alerts, and more), and default menus have been localized into Japanese, French, German, Chinese (traditional and simplified), Italian, Spanish, Korean, Portuguese, and Russian.
  • IME (Input Method Editor) support: This allows users to input characters not present on their keyboards.
  • New APIs: The AIR 1.1 runtime contains the new Capabilities.languages property which returns an array containing information about the user's preferred languages.
  • Framework support: Flex 3 already contains runtime localization support, although there's an ActionScript library referenced below that makes dynamically localizing your Adobe AIR applications even easier. There's also an entire JavaScript localization framework included in the AIR SDK for localizing HTML applications.

The first three items above work automatically. In other words, as a developer, there's nothing you need to do in order to get non-English characters to render correctly in AIR applications. Additionally, runtime strings are automatically displayed to end users in the most appropriate language, and IMEs just work. Therefore, this article focuses on the code developers do have to worry about in order to localize their AIR applications.

Apprise was the first AIR application I localized, so I learned a lot during the process. I discovered that there are really three steps to the process:

  1. Picking the most appropraite language.
  2. Telling Flex which language to use.
  3. Replacing strings and date masks.

Choosing the most appropriate language

Flex 3 provides runtime localization support, which works great in AIR. Runtime localization support means that you don't have to distribute a different .air file for each language you support. Rather, you can distribute a single .air file which contains resource bundles with strings translated into all the languages you support. The application can then dynamically tell Flex which language to use, and if the code was written correctly, the entire user interface will adapt itself automatically.

There are two ways to figure out which language your application should use:

  • Let users pick the language themselves. Your application might provide a select box or a menu with all the supported languages, allowing the end user to pick the language he or she is most comfortable with.
  • Query the operating system for the most appropriate language.

I chose to use the second approach in Apprise.

AIR 1.1 adds the new languages property to the flash.system.Capabilities class which returns an array of preferred languages as specified by the operating system. So now you know which languages the end user prefers, and of course you aleady know which languages your application supports, but you still have a problem: how do you put those two lists together to decide on the best language to use?

The problem is trickier than it initially seems, because the language information returned by the OS may or may not contain region information. Likewise, your own language packs also may or may not include region information. Eventually, the Flex framework will solve this problem for you (the changes are already checked into the public Flex source code repository, but they haven't yet made it into an official release); for now, we recommend using as3localelib. The as3locatelib project contains a class called LocaleUtil, which has a single static function called sortLanguagesByPreference. The sortLanguagesByPreference function takes an array of languages that you support, an array of languages representing the system preferences, and a "fallback" locale to be used in case there is no good option.

The code in Apprise looks like this:

var sortedLocales:Array = LocaleUtil.sortLanguagesByPreference(['de', 'en_US', 'es', 'fr', 'it', 'ja_JP', 'ko', 'pt', 'ru', 'zh_Hans', 'zh_Hant'], Capabilities.languages, "en_US");

For more information on as3localelib and to download the code for your project, check out the as3locale project page on Google Code.

Telling Flex which language to use

Now that you have a list of languages sorted by both what your application supports and the end user's preferences, all you have to do is tell the Flex framework which language the application should use (and therefore which resource bundles should be used). The localeChain property of the ResourceManager class tells Flex the order of the resource bundles to pull strings out of.

In Apprise, the code looks like this:

ResourceManager.getInstance().localeChain = sortedLocales;

Replacing Strings and Date Masks

Since Apprise was originally written for AIR 1.0 (which did not include localization support), I had to go back and replace hardcoded strings with strings dynamically loaded from resource bundles. Resource bundles are files (or resources) that contain name/value pairs arranged in a conventional directory structure which Flex knows to look for. For example, in my Apprise src directory (shown in Figure 2), I created the directory "locale" inside of which I created a directory for each language Apprise supports. Inside of those directories, I created resource files with name/value pairs like this:

FEEDINFO_FEED_NAME_ITEM=Feed Name FEEDINFO_DATE_MASK=EEEE, MMMM D @ L:NN A
The Apprise src directory
Figure 2. The Apprise src directory

Of course, for the non-English resources, these name/value pairs are translated appropriately.

I'm not going to get into a lot of detail on how this works because there's already an excellent article called Localizing Flex Applications, which tells you everything you need to know about the Flex 3 runtime localization feature. But I'll show you a few examples.

Throughout my code, I changed labels that looked like this:

<mx:Label text="Post Title"/>

to this:

<mx:Label text="{resourceManager.getString('resources', 'POSTDISPLAY_POST_TITLE')}"/>

I also localized my date masks, so rather than this:

dateFormatter.formatString = "EEEE, MMMM D @ L:NN A";

I used something like this:

dateFormatter.formatString = resourceManager.getString('resources', 'POSTGRID_DATE_FORMATTER');

That's about all that goes into localizing an AIR 1.1 application written in Flex. We also provide an excellent localization framework for HTML applications which you can read about in the Quick Start article, Building a multilingual HTML-based application.

More Like This

  • Using the Microphone capabilities in Adobe AIR 2
  • Using the SQLite database access API in Adobe AIR
  • Writing multiscreen AIR apps
  • Creating a socket server in Adobe AIR 2
  • User experience considerations with SQLite operations
  • Exploring the new file capabilities in Adobe AIR 2
  • Reducing CPU usage in Adobe AIR
  • Resolving DNS records in Adobe AIR 2
  • Using drag-and-drop support of remote files in Adobe AIR 2
  • Retrieving a list of network interfaces in Adobe AIR 2

Tutorials & Samples

Tutorials

  • Retrieving a list of network interfaces in Adobe AIR 2
  • Using the AIR 2 NativeProcess API to create a screen recorder
  • Writing multiscreen AIR apps
  • Resolving DNS records in Adobe AIR 2

Samples

  • Using the Salesbuilder Adobe AIR sample application

Adobe AIR Forums

More
04/11/2012 Surround sound 5.1 with Air 3.2 on desktop app?
12/12/2011 Live Streaming H.264 Video on iOS using AIR
04/17/2012 HTMLLoader - Google Maps?
04/12/2012 Tabindex in forms on mobile?

Adobe AIR Blog

More
07/09/2012 Protected: Publishing Adobe AIR 3.0 for TV on Reference Devices
07/08/2012 Source Code: Adobe AIR 3.3 Retina Video Application
07/06/2012 Application specific File Storage on Adobe AIR based ios Application
07/04/2012 Recent Work - iPad/Android App: Inside My toyota

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement