How to Check the System Language using ActionScript

by Duncan Murray.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on flash  

You are here: Categories » Computers and technology » Flash

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");
 
Leave a comment or ask a question
Total comments: 0

Flash Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
How to build an animated button using Flash - Time: 15 Minutes. Difficulty Level: Intermediate Requirements: Flash 8 Assumed Knowledge: Basic action (more...)
Enhancing Standalone Projector - You want to create an enhanced Standalone Projector with features such as borderless playback, custom titles, no Flash menus, and so on. Use a third-party tool such as SWF Studio or SWFKit to c (more...)
Creating Flash Buttons - Buttons are one of the three main types of symbols that you use in Flash. The others are movie clips and graphics. Making a New Button There are many ways to create a button. One (more...)
Bouncing Ball Script - Start a new Flash movie. Create a movie clip that has a ball graphic inside it. You can name the instance of the movie clip, myClip, but our code will not depend on the name of the clip. (more...)
ActionScript: Creating Reusable Code - You want to perform a series of actions at various times without duplicating code unnecessarily throughout your movie. Create a function and then call (i.e., invoke) it by name whenever you (more...)
3D Scaling with ActionScript - Although Flash is not capable of real 3D graphics, the kind seen in popular computer games, you can create the illusion of 3D by using scaling. Scaling an object is a great way to give your (more...)
The Dot Syntax - Something else that you will be seeing a lot of as you learn ActionScript is dot syntax. Dot syntax is a way of grouping objects and functions that is used in many object-oriented programming (more...)
Movie Clip Scripts - Movie clip scripts, like button scripts, use handlers. Instead of using the on keyword that button scripts use, we will use the onClipEvent keyword. Here is an example of a movie clip script: (more...)
Decoding an RGB Value - You want to extract the red, green, and blue components from an RGB value returned by Color.getRGB( ). Use the bitshift right and bitwise AND operators. You can extract the red, gre (more...)
ActionScript: Generalizing a Function to Enhance Reusability - You want to perform slight variations of an action without having to duplicate multiple lines of code to accommodate the minor differences. Add parameters to your function to make it flexib (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.