| Package | andromeda.i18n |
| Class | public class Localization |
| Inheritance | Localization CoreEventDispatcher CoreObject |
| Implements | Identifiable |
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.
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
| Property | Defined by | ||
|---|---|---|---|
| CHANGE : String [static]
The name of the event when the localization is changed.
| Localization | ||
![]() | channel : 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 | ||
![]() | isGlobal : 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 | ||
| Method | Defined by | ||
|---|---|---|---|
|
Localization(id:* = null, bGlobal:Boolean = false, sChannel:String = null)
Creates a new Localization instance.
| Localization | ||
![]() |
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 | ||
![]() |
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
| CoreEventDispatcher | |
|
Returns the current
Locale object defines with the specified Lang object in argument. | Localization | ||
![]() |
Returns the internal
EventDispatcher reference. | CoreEventDispatcher | |
|
getEventTypeCHANGE():String
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 | ||
![]() |
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 | ||
![]() |
Returns the internal
ILogger reference of this ILogable object. | CoreObject | |
![]() |
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
| CoreEventDispatcher | |
![]() |
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 | ||
![]() |
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 | ||
![]() |
isLocked():Boolean
Returns
true if the object is locked. | CoreEventDispatcher | |
![]() |
lock():void
Locks the object.
| CoreEventDispatcher | |
|
notifyChange():void
Notify when the Localization change.
| Localization | ||
|
Puts the specified Locale object with the passed-in Lang reference.
| Localization | ||
![]() |
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 | ||
![]() |
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
| CoreEventDispatcher | |
![]() |
setEventDispatcher(e:EventDispatcher):void
Sets the internal
EventDispatcher reference. | CoreEventDispatcher | |
|
setEventTypeCHANGE(type:String):void
Returns the event type use in the notifyChange ethod.
| Localization | ||
![]() |
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 | |
![]() |
Sets the internal
ILogger reference of this ILogable object. | CoreObject | |
|
size():uint
Returns the number of Lang elements in the Localization singleton.
| Localization | ||
![]() |
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 | ||
![]() |
unlock():void
Unlocks the display.
| CoreEventDispatcher | |
![]() |
unregisterEventListener(type:String, listener:Boolean, useCapture:* = false):void
Removes a listener (Function or EventListener object) from the EventDispatcher object.
| CoreEventDispatcher | |
![]() |
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 | |
| CHANGE | property |
public static var CHANGE:StringThe name of the event when the localization is changed.
| current | property |
current:* [read-write]
(read-write) Indicates the current Lang object selected in the current localization.
public function get current():*
public function set current(value:*):void
| DEFAULT_ID | property |
public static var DEFAULT_ID:String = "default"The default singleton name of the Localization singletons.
| id | property |
id:* [read-write](read-write) Returns the id of this object.
Implementation public function get id():*
public function set id(value:*):void
| loader | property |
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
| throwError | property |
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
| Localization | () | constructor |
public function Localization(id:* = null, bGlobal:Boolean = false, sChannel:String = null)Creates a new Localization instance.
Parametersid:* (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.
|
| append | () | method |
public function append(lang:*, o:*):BooleanAppend 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.
Parameterslang:* — 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.
|
Boolean — true if the append process is done.
|
| clear | () | method |
public function clear():voidRemoves 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.
lang:* |
Boolean — true 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.
lang:* |
Locale —
the current Locale object defines with the specified Lang object in argument.
|
| getEventTypeCHANGE | () | method |
public function getEventTypeCHANGE():StringReturns the event name use in the notifyChange method.
ReturnsString — 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.
id:String (default = null) |
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.
Parametersid:String (default = null) — (optional) if this key is specified the method return the value of the specified key in the current locale object.
|
* — the locale object with all this properties.
|
| init | () | method |
public function init(o:Object, sID:String = null, callback:Function = null):voidApply the current localization over the specified object.
Parameterso: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.
Boolean — true if the Localization model is empty.
|
| notifyChange | () | method |
public function notifyChange():voidNotify when the Localization change.
| put | () | method |
public function put(lang:*, oL:Locale):*Puts the specified Locale object with the passed-in Lang reference.
Parameterslang:* |
|
oL:Locale |
* |
| release | () | method |
public static function release(id:String):Localization
Releases the specified Localization singleton with the specified name in argument.
id:String |
Localization —
the reference of the removed Localization object.
|
| remove | () | method |
public function remove(lang:*):*Removes the specified Lang in the Localization model.
Parameterslang:* — a valid Lang object. This argument is valid if the Lang.validate method return true.
|
* — The removed Locale object or null.
|
| setEventTypeCHANGE | () | method |
public function setEventTypeCHANGE(type:String):voidReturns the event type use in the notifyChange ethod.
Parameterstype:String |
| size | () | method |
public function size():uintReturns the number of Lang elements in the Localization singleton.
Returnsuint — the number of Lang elements in the Localization singleton.
|
| toString | () | method |
public override function toString():String
Returns the String representation of this object.
String — the String representation of this object.
|