2.3. Checking the System Language

Problem

You want to know what language is used on the computer playing the movie.

Solution

Use the System.capabilities.language property.

Discussion

You can use the System.capabilities.language property to determine the language of the computer that is playing the movie. The property returns a two-letter ISO-639-1 language code (i.e., “fr” for French). Where applicable, a two-letter country code is appended, separated from the language code with a hyphen (i.e., “en-US” for U.S. English and “en-UK” for U.K. English).

For a summary of language codes, see the following resources:

http://lcweb.loc.gov/standards/iso639-2/englangn.html
http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html

Here is an example of how to use the language property:

// Example output: en-US
trace(System.capabilities.language);

You can use this property to dynamically load content in the appropriate language:

// Create an associative array with language codes 
// for the keys and greetings for the values.
greetings = new Array(  );
greetings["en"] = "Hello";
greetings["es"] = "Hola";
greetings["fr"] = "Bonjour";

// Extract the first two characters from the language code.
lang = System.capabilities.language.substr(0, 2);

// Use a default language if the language is not in the list.
if (greetings[lang] == undefined) {
  lang = "en";
}

// Display the greeting in the appropriate language.
trace(greetings[lang]);

When you want to offer multiple language capabilities ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.