13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Internationalizing applications<br />

The values retrieved from these methods and properties can reflect additional information that cannot be extracted<br />

directly from the locale id<strong>en</strong>tifier about the locale.<br />

Wh<strong>en</strong> an application creates a locale-aware service, such as a date formatter, it must specify the int<strong>en</strong>ded locale. The<br />

list of supported locales varies from one operating system to another; h<strong>en</strong>ce, the requested locale can be unavailable.<br />

Flash Player first tries to match the language code of the locale that you requested. Th<strong>en</strong> it tries to refine the locale by<br />

finding a matching writing system (script) and region. For example:<br />

var loc:LocaleID = new LocaleID("es");<br />

trace(loc.getLanguage()); // es<br />

trace(loc.getScript()); // Latn<br />

trace(loc.getRegion()); // ES<br />

In this example, the LocaleID() constructor retrieved data about the locale that best matches the language code “es”<br />

for that user.<br />

Setting the locale ID<br />

There are a number of ways to set the curr<strong>en</strong>t locale for an application, including:<br />

Hard-code a single locale ID into the application. This approach is common, but it does not support<br />

internationalization of the application.<br />

Use the locale ID prefer<strong>en</strong>ces from the user’s operating system, or browser, or other user prefer<strong>en</strong>ces. This<br />

technique usually results in the best locale settings for the user, but it is not always accurate. There is a risk that the<br />

operating system settings do not reflect the user’s actual prefer<strong>en</strong>ces. For example, the user could be using a shared<br />

computer and be unable to change the operating system’s preferred locales.<br />

After setting the locale ID based on the user’s prefer<strong>en</strong>ces, let the user select from a list of supported locales. This<br />

strategy is normally the best option if your application can support more than one locale.<br />

You can implem<strong>en</strong>t this third option as follows:<br />

1 Retrieve a list of the user’s preferred locales or languages from a user profile, browser settings, operating system<br />

settings, or a cookie. (Your application would need to implem<strong>en</strong>t this logic itself. The flash.globalization library<br />

does not support reading such prefer<strong>en</strong>ces directly.)<br />

2 Determine which of those locales your application supports and select the best one by default. Use the method<br />

LocaleID.determinePreferredLocales() to find the best locales for a user based on their preferred locales and the<br />

locales supported by the operating system.<br />

3 Give the user a way to change the default locale setting in case the default locale is not satisfactory.<br />

Limitations of other locale and language classes<br />

The fl.lang.Locale class lets you replace text strings based on a locale, using resource bundles containing string<br />

values. However this class does not support other internationalization features such as number, curr<strong>en</strong>cy, or date<br />

formatting, sorting and matching, and so on. In addition, this class is only available with Flash Professional.<br />

You can also retrieve the curr<strong>en</strong>t language code setting for the operating system using the<br />

flash.system.Capabilities.language property. However, this property retrieves only the two-character ISO<br />

639-1 language code—not the full locale ID—and it only supports a specific set of locales.<br />

With AIR 1.5, you can use the flash.system.Capabilities.languages property. This property provides an array<br />

of the user’s preferred user interface languages. Thus, it does not have the limitations of Capabilities.language.<br />

Last updated 6/6/2012<br />

942

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!