|   |      Tweet | 
var r:SystemManager = new SystemManager(); var t:Locale = (r.topLevelSystemManager) ? Locale.getCurrent(r.topLevelSystemManager) : Locale.getCurrent(r);
====== WwnaviRs.as (Resource loading class) ======
 //$NLS-WWNAVI 2011-06-13T20:24:27+0900
package 
{
	
	import flash.system.Capabilities;
	import flash.external.ExternalInterface;
	import mx.resources.ResourceManager;
	
	/**
	 * This class is automatically generated by wwnavi.
	 */
	
	[ResourceBundle("wwnaviRs")]
	public class WwnaviRs
	{
		private static var isInit:Boolean = false;
		
		private static var  loc:String = null;
		
		public static function init():void
		{
			
			// Get user system language code (without country codes in most cases).
			
			loc = Capabilities.language;
			loc = loc.replace("-", "_");
			
			var cn:String = "";
			
			// For using this code,  the additional compile option, 
			// '-locale=YOUR_LOCALE(e.g. en_US) -source-path=YOUR_RESOURCE_PATH(e.g. locale)/{locale}' is required.
			// If you add other locales, you have to add them to the option above.
			
			switch (loc) {
			case "en":	
			    cn = "US";
			    break;
			case "ja":	
			    cn = "JP";
			    break;
			case "ko":	
			    cn = "KR";
			    break;
			case "zh":	
			    // do nothing. (loc has "_CN or _TW")
			    break;
			// add your locale country codes.
			//case...
			//    break;
			default:			    
			}
			
			if (loc.indexOf("_") == -1) {
				loc = loc + "_" + cn;
			}
			
			// Or get user browser language by your external JavaScript.
			// loc = getBrowserLang();
			
			// In some cases, this code doesn't work.
			ResourceManager.getInstance().localeChain = [loc];
			
			isInit = true;
		}
		
		Get user locales from the HTML parameter.
		public static function initByFlashVars(flashVars:Object):void
		{
			loc = flashVars["locale"];
			isInit = true;
		}
		
		public static function getString(id:String):String 
		{
			if (!isInit) init();
			// ResourceManager.getInstance().localeChain = [loc]
			// doesn't affect in some cases, so we added the following code.
			var str:String = ResourceManager.getInstance().getString("wwnaviRs", id, null, loc);
			if (str == null) str = ResourceManager.getInstance().getString("wwnaviRs", id);
			return str;
		}
		
	    /*public function getBrowserLang():String {
            var s:String;
            if (ExternalInterface.available) {
               var wrapperFunction:String = "YOUR_JAVASCRIPT_FUNCTION";
               s = ExternalInterface.call(wrapperFunction);
            } else {
               s = "Wrapper not available";
            }
           return s;
        }*/
		
	}
	
}
====== test.html (loading Flash) ======
<html>
<object width="100%" height="100%" >
<!-- Edit locale to the suitable one. -->
<param name="FlashVars" value="locale=ja_JP" />
<!-- Edit locale to the suitable one. -->
<embed  width="100%" height="100%" src="Main.swf" FlashVars="locale=ja_JP" />
</object>
</html>
====== Main.as (Getting locales from HTML) ======
Write the process in entry points (e.g. Main).
public function Main():void
{     WwnaviRs.initByFlashVars(this.root.loaderInfo.parameters);
====== Main.as (String loading function) ======
...
tx1.text = WwnaviRs.getString("Main.1"); // tx1.text = "This is text 1."; 
...
====== Resource File Location ======
../locale/en_US/wwnaviRs.properties
          ja_JP/wwnaviRs.properties
           ...
../src/Main.as
        WwnaviRs.as
        
====== Resource File Contents ======
Main.3=This is text 3.
Main.2=This is text 2.
Main.1=This is text 1.
...
Main.3=これはテキスト3です。
Main.2=これはテキスト2です。
Main.1=これはテキスト1です。
====== Compiler Options ======
-locale=en_US,ja_JP -source-path=locale/{locale}
 
Go to Internationalization Programming Top