Packagevegas.i18n
Classpublic class Localization
InheritanceLocalization Inheritance CoreEventDispatcher Inheritance Object
Implements Identifiable

The Localization class allows to manage via textual files with 'JSON' or 'eden' format to charge the textual contents of an application according to the parameters of languages chosen by the users.

It is possible to define several singletons of the Localization class to manage several elements in the application, but for this it's necessary to use the static property getInstance(sName). Thus all the authorities become of Singletons reusable a little everywhere in the application rather quickly.

Example :

     import system.events.ActionEvent ;
     import system.eden ;
     
     import vegas.i18n.EdenLocalizationLoader ;
     import vegas.i18n.Lang ;
     import vegas.i18n.Locale ;
     import vegas.i18n.Localization ;
     
     import vegas.events.LocalizationEvent ;
     
     var debug:Function = function( e:Event ):void
     {
         trace("------- " + e.type ) ;
     }
     
     var change:Function = function( e:LocalizationEvent )
     {
         var target:Localization = e.getTarget() ;
         var current:Lang  = e.current ;
         var locale:Locale = e.getLocale() ;
         trace("# change current " + current ) ;
         trace("# change locale  " + locale  ) ;
         trace( eden.serialize( locale ) ) ;
     }
     
     var localization:Localization  = Localization.getInstance() ;
     localization.addEventListener( LocalizationEvent.CHANGE , change ) ;
     
     var loader:EdenLocalizationLoader = localization.loader as EdenLocalizationLoader ;
     loader.addEventListener( ActionEvent.START , debug ) ;
     loader.addEventListener( ActionEvent.FINISH , debug ) ;
     loader.path = "locale/" ;
     
     localization.current = Lang.FR ;
     
     var onKeyDown:Function = function( e:KeyboardEvent ):void
     {
         var code:uint = e.keyCode ;
         switch( code )
         {
             case Keyboard.UP :
             {
                 localization.current = Lang.EN ;
                 break ;
             }
             case Keyboard.DOWN :
             {
                 localization.current = "fr" ;
                 break ;
             }
         }
     }
     stage.addEventListener( KeyboardEvent.KEY_DOWN , onKeyDown ) ; 
     

See also

vegas.i18n.Lang
vegas.i18n.Locale


Public Properties
 PropertyDefined By
  CHANGE : String
[static] The name of the event when the localization is changed.
Localization
 Inheritedchannel : String
[read-only] Indicates the channel of this dispatcher if this instance is global.
CoreEventDispatcher
  current : *
(read-write) Indicates the current Lang object selected in the current localization.
Localization
  DEFAULT_ID : String = default
[static] The default singleton name of the Localization singletons.
Localization
  id : *
Indicates the id value of this object.
Localization
  loader : ILocalizationLoader
Returns the internal ILocalizationLoader reference of the Localization singleton.
Localization
  throwError : Boolean
Indicates if the class throws errors or return null when an error is throwing.
Localization
Public Methods
 MethodDefined By
  
Localization(id:* = null, global:Boolean = false, channel:String = null)
Creates a new Localization instance.
Localization
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0.0, useWeakReference:Boolean = false):void
Allows the registration of event listeners on the event target.
CoreEventDispatcher
  
append(lang:*, o:*):Boolean
Append the specified dynamic object values with the specificied lang value.
Localization
  
clear():void
Removes all singletons in the internal map of this object..
Localization
  
contains(lang:*):Boolean
Returns true if this Localization contains the specified Lang.
Localization
 Inherited
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
CoreEventDispatcher
  
get(lang:*):Locale
Returns the current Locale object defines with the specified Lang object in argument.
Localization
 Inherited
Returns the internal system.events.EventDispatcher reference.
CoreEventDispatcher
  
Returns the event name use in the notifyChange method.
Localization
  
getInstance(id:String = null):Localization
[static] Returns a Localization singleton reference with the specified id passed-in argument.
Localization
  
getLocale(id:String = null):*
Returns the locale object with all this properties.
Localization
 Inherited
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
CoreEventDispatcher
  
init(o:Object, sID:String = null, callback:Function = null):void
Apply the current localization over the specified object.
Localization
  
isEmpty():Boolean
Returns true if the Localization model is empty.
Localization
 Inherited
isGlobal():Boolean
Indicates if the dispatcher use a global event flow.
CoreEventDispatcher
 Inherited
isLocked():Boolean
Returns true if the object is locked.
CoreEventDispatcher
 Inherited
lock():void
Locks the object.
CoreEventDispatcher
  
Notify when the Localization change.
Localization
  
put(lang:*, oL:Locale):*
Puts the specified Locale object with the passed-in Lang reference.
Localization
 Inherited
registerEventListener(type:String, listener:*, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Allows the registration of event listeners on the event target (Function or EventListener).
CoreEventDispatcher
  
[static] Releases the specified Localization singleton with the specified name in argument.
Localization
  
remove(lang:*):*
Removes the specified Lang in the Localization model.
Localization
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
CoreEventDispatcher
 Inherited
Sets the internal EventDispatcher reference.
CoreEventDispatcher
  
setEventTypeCHANGE(type:String):void
Returns the event type use in the notifyChange ethod.
Localization
 Inherited
setGlobal(flag:Boolean = false, channel:String = null):void
Sets if the instance use a global system.events.EventDispatcher to dispatch this events, if the flag value is false the instance use a local EventDispatcher.
CoreEventDispatcher
  
size():uint
Returns the number of Lang elements in the Localization singleton.
Localization
  
toString():String
Returns the String representation of this object.
Localization
 Inherited
unlock():void
Unlocks the display.
CoreEventDispatcher
 Inherited
unregisterEventListener(type:String, listener:*, useCapture:Boolean = false):void
Removes a listener (Function or EventListener object) from the EventDispatcher object.
CoreEventDispatcher
 Inherited
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
CoreEventDispatcher
Protected Methods
 MethodDefined By
 Inherited
Creates and returns the internal EventDispatcher reference (this method is invoked in the constructor).
CoreEventDispatcher
Property Detail
CHANGEproperty
public static var CHANGE:String

The name of the event when the localization is changed.

currentproperty 
current:*

(read-write) Indicates the current Lang object selected in the current localization.


Implementation
    public function get current():*
    public function set current(value:any):void
DEFAULT_IDproperty 
public static var DEFAULT_ID:String = default

The default singleton name of the Localization singletons.

idproperty 
id:*

Indicates the id value of this object.


Implementation
    public function get id():*
    public function set id(value:any):void
loaderproperty 
loader:ILocalizationLoader

Returns the internal ILocalizationLoader reference of the Localization singleton.


Implementation
    public function get loader():ILocalizationLoader
    public function set loader(value:ILocalizationLoader):void
throwErrorproperty 
public var throwError:Boolean

Indicates if the class throws errors or return null when an error is throwing.

Constructor Detail
Localization()Constructor
public function Localization(id:* = null, global:Boolean = false, channel:String = null)

Creates a new Localization instance.

Parameters
id:* (default = null) — the id of the object.
 
global:Boolean (default = false) — the flag to use a global event flow or a local event flow.
 
channel:String (default = null) — the name of the global event flow if the bGlobal argument is true.
Method Detail
append()method
public function append(lang:*, o:*):Boolean

Append the specified dynamic object values with the specificied lang value. If no exist a Locale Object with the specified lang id, a Locale Object is created.

Parameters

lang:* — The language id, must be a String (valid in the Lang class) or a Lang object.
 
o:* — The dynamic object used to append the Locale object of the specified lang.

Returns
Booleantrue if the append process is done.
clear()method 
public function clear():void

Removes all singletons in the internal map of this object..

contains()method 
public function contains(lang:*):Boolean

Returns true if this Localization contains the specified Lang.

Parameters

lang:*

Returns
Booleantrue if this Localization contains the specified Lang.
get()method 
public function get(lang:*):Locale

Returns the current Locale object defines with the specified Lang object in argument.

Parameters

lang:*

Returns
Locale — the current Locale object defines with the specified Lang object in argument.
getEventTypeCHANGE()method 
public function getEventTypeCHANGE():String

Returns the event name use in the notifyChange method.

Returns
String — the event name use in the notifyChange method.
getInstance()method 
public static function getInstance(id:String = null):Localization

Returns a Localization singleton reference with the specified id passed-in argument.

Parameters

id:String (default = null)

Returns
Localization — a Localization singleton reference with the specified id passed-in argument.
getLocale()method 
public function getLocale(id:String = null):*

Returns the locale object with all this properties.

Parameters

id:String (default = null) — (optional) if this key is specified the method return the value of the specified key in the current locale object.

Returns
* — the locale object with all this properties.
init()method 
public function init(o:Object, sID:String = null, callback:Function = null):void

Apply the current localization over the specified object.

Parameters

o:Object — The object to fill with the current localization in the application.
 
sID:String (default = null) — (optional) if this key is specified the method return the value of the specified key in the current locale object.
 
callback:Function (default = null) — (optional) The optional method to launch after the initialization over the specified object.

isEmpty()method 
public function isEmpty():Boolean

Returns true if the Localization model is empty.

Returns
Booleantrue if the Localization model is empty.
notifyChange()method 
public function notifyChange():void

Notify when the Localization change.

put()method 
public function put(lang:*, oL:Locale):*

Puts the specified Locale object with the passed-in Lang reference.

Parameters

lang:*
 
oL:Locale

Returns
*
release()method 
public static function release(id:String):Localization

Releases the specified Localization singleton with the specified name in argument.

Parameters

id:String

Returns
Localization — the reference of the removed Localization object.
remove()method 
public function remove(lang:*):*

Removes the specified Lang in the Localization model.

Parameters

lang:* — a valid Lang object. This argument is valid if the Lang.validate method return true.

Returns
* — The removed Locale object or null.
setEventTypeCHANGE()method 
public function setEventTypeCHANGE(type:String):void

Returns the event type use in the notifyChange ethod.

Parameters

type:String

size()method 
public function size():uint

Returns the number of Lang elements in the Localization singleton.

Returns
uint — the number of Lang elements in the Localization singleton.
toString()method 
public function toString():String

Returns the String representation of this object.

Returns
String — the String representation of this object.