Packageandromeda.i18n
Classpublic class Localization
InheritanceLocalization Inheritance CoreEventDispatcher Inheritance CoreObject
ImplementsIdentifiable

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 andromeda.events.ActionEvent ;
     
     import andromeda.i18n.EdenLocalizationLoader ;
     import andromeda.i18n.Lang ;
     import andromeda.i18n.Locale ;
     import andromeda.i18n.Localization ;
     
     import andromeda.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.getCurrent() ;
         var locale:Locale = e.getLocale() ;
         trace("# change current " + current ) ;
         trace("# change locale  " + locale  ) ;
         for (var each:String in locale)
         {
             trace("  " + each + " : " + locale[each]) ;
             for (var prop:String in locale[each])
             {
                 trace("    " + prop + " : " + locale[each][prop]) ;
             }
         }
     }
     
     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

andromeda.i18n.Lang
andromeda.i18n.Locale


Public Properties
 PropertyDefined by
  CHANGE : String
[static] The name of the event when the localization is changed.
Localization
 Inheritedchannel : String
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 : *
(read-write) Returns the id of this object.
Localization
 InheritedisGlobal : Boolean
(read-only) Returns the value of the isGlobal flag of this model.
CoreEventDispatcher
  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, bGlobal:Boolean = false, sChannel: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 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 name passed-in argument.
Localization
 Inherited
getIsGlobal():Boolean
Returns the value of the isGlobal flag of this model.
CoreEventDispatcher
  
getLocale(id:String = null):*
Returns the locale object with all this properties.
Localization
 Inherited
Returns the internal ILogger reference of this ILogable object.
CoreObject
 Inherited
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
CoreEventDispatcher
 Inherited
hashCode():uint
Returns a hashcode value for the object.
CoreObject
  
init(o:Object, sID:String = null, callback:Function = null):void
Apply the current localization over the specified object.
Localization
 Inherited
Creates and returns the internal EventDispatcher reference (this method is invoked in the constructor).
CoreEventDispatcher
  
isEmpty():Boolean
Returns true if the Localization model is empty.
Localization
 Inherited
isLocked():Boolean
Returns true if the object is locked.
CoreEventDispatcher
 Inherited
lock():void
Locks the object.
CoreEventDispatcher
  
notifyChange():void
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:Boolean, useCapture:int = false, priority:Boolean = 0, useWeakReference:* = false):void
Allows the registration of event listeners on the event target (Function or EventListener).
CoreEventDispatcher
  
release(id:String):Localization
[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 EventDispatcher to dispatch this events, if the flag value is false the instance use a local EventDispatcher.
CoreEventDispatcher
 Inherited
setLogger(log:ILogger = null):void
Sets the internal ILogger reference of this ILogable object.
CoreObject
  
size():uint
Returns the number of Lang elements in the Localization singleton.
Localization
 Inherited
toSource(indent:int = 0):String
Returns the string representation the source code of the object.
CoreEventDispatcher
  
toString():String
Returns the String representation of this object.
Localization
 Inherited
unlock():void
Unlocks the display.
CoreEventDispatcher
 Inherited
unregisterEventListener(type:String, listener:Boolean, useCapture:* = 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
Property detail
CHANGEproperty
public static var CHANGE:String

The name of the event when the localization is changed.

currentproperty 
current:*  [read-write]

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

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

The default singleton name of the Localization singletons.

idproperty 
id:*  [read-write]

(read-write) Returns the id of this object.

Implementation
    public function get id():*
    public function set id(value:*):void
loaderproperty 
loader:ILocalizationLoader  [read-write]

Returns the internal ILocalizationLoader reference of the Localization singleton.

Implementation
    public function get loader():ILocalizationLoader
    public function set loader(value:ILocalizationLoader):void
throwErrorproperty 
throwError:Boolean  [read-write]

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

Implementation
    public function get throwError():Boolean
    public function set throwError(value:Boolean):void
Constructor detail
Localization()constructor
public function Localization(id:* = null, bGlobal:Boolean = false, sChannel:String = null)

Creates a new Localization instance.

Parameters
id:* (default = null) — the id of the object.
 
bGlobal:Boolean (default = false) — the flag to use a global event flow or a local event flow.
 
sChannel: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 name passed-in argument.

Parameters
id:String (default = null)

Returns
Localization — a Localization singleton reference with the specified name 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 override function toString():String

Returns the String representation of this object.

Returns
String — the String representation of this object.