| Package | vegas.i18n |
| Class | public class Localization |
| Inheritance | Localization CoreEventDispatcher Object |
| 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.
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
| Property | Defined By | ||
|---|---|---|---|
| CHANGE : String [static]
The name of the event when the localization is changed. | Localization | ||
![]() | channel : 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 | ||
| Method | Defined By | ||
|---|---|---|---|
Localization(id:* = null, global:Boolean = false, channel: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 system.events.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 id passed-in argument. | Localization | ||
getLocale(id:String = null):*
Returns the locale object with all this properties. | Localization | ||
![]() | 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 | ||
![]() | isGlobal():Boolean
Indicates if the dispatcher use a global event flow. | CoreEventDispatcher | |
![]() | 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:*, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = 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(dispatcher: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 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 | ||
![]() | unlock():void
Unlocks the display. | CoreEventDispatcher | |
![]() | unregisterEventListener(type:String, listener:*, useCapture:Boolean = 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) Indicates the current Lang object selected in the current localization.
public function get current():* public function set current(value:any):void| DEFAULT_ID | property |
public static var DEFAULT_ID:String = defaultThe default singleton name of the Localization singletons.
| id | property |
id:*Indicates the id value of this object.
public function get id():* public function set id(value:any):void| loader | property |
loader:ILocalizationLoaderReturns the internal ILocalizationLoader reference of the Localization singleton.
public function get loader():ILocalizationLoader public function set loader(value:ILocalizationLoader):void| throwError | property |
public var throwError:BooleanIndicates if the class throws errors or return null when an error is throwing.
| Localization | () | Constructor |
public function Localization(id:* = null, global:Boolean = false, channel:String = null)Creates a new Localization instance.
Parametersid:* (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.
|
| 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.
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.
|
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.
Parameters
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.
Parameters
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 id passed-in argument.
Parameters
id:String (default = null) |
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.
|
* — 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.
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.
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.
Parameters
lang:* | |
oL:Locale |
* |
| release | () | method |
public static function release(id:String):Localization
Releases the specified Localization singleton with the specified name in argument.
Parameters
id:String |
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.
|
* — The removed Locale object or null.
|
| setEventTypeCHANGE | () | method |
public function setEventTypeCHANGE(type:String):voidReturns the event type use in the notifyChange ethod.
Parameters
type: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 function toString():String
Returns the String representation of this object.
String — the String representation of this object.
|