How to Check the System Language using ActionScript

written by: Duncan Murray; article published: year 2007, month 07;

In: Root » Computers and technology » Flash

  Share  
|
  PL  |  NL  |  FR  |  ES  |  PT  |  IT  |  DE  |  DK  |  NO  |  SE  |  FI  |  GR  |  JP  |  CN  |  KR  |  RU  |  AE


You want to know what language is used on the computer playing the movie. Use the System.capabilities.language property.

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 in your movies, you can choose from several different approaches. One approach, as shown in the preceding code, is to create associative arrays for all the text that appears in the movie. Another is to create static content in multiple movies (one for each language) and load those movies based on the language code. With this technique, each .swf filename should include the language code, such as myMovie_en.swf, myMovie_es.swf, myMovie_fr.swf, etc.

// Get the language from the capabilities object.
   lang = System.capabilities.language.substr(0, 2);
// Create an array of the languages you are supporting (i.e., the languages for which
   // you have created movies).
   supportedLanguages = ["en", "es", "fr"];
// Set a default language in case you don't support the user's language.
   useLang = "en";
// Loop through the supported languages to find a match to the user's language. If
   // you find one, set useLang to that value and then exit the for statement.
   for (var i = 0; i < supportedLanguages.length; i++) {
   if (supportedLanguages[i] == lang) {
   useLang = lang;
   break;
   }
   }
// Load the corresponding movie.
   _root.loadMovie("myMovie_" + useLang + ".swf");
 

Share

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us or use the "Report this article" button on this page to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.