Packageqnx.locale
Classpublic class LocaleResourceBundle
InheritanceLocaleResourceBundle Inheritance flash.events.EventDispatcher

The LocaleResourceBundle class loads and parses localized String files.

The following parsing rules are supported:

The Strings that you specify in the resource file can also contain wildcards. Each wildcard is replaced at load-time with the String value that you specify as an argument to the getResource method. For example, the resource String below contains the String (a name) "Westlee Barichuk" and two wildcards, preceding and following the name:

     full-name= %1% Westlee Barichuk  %2%
     

You can replace the wildcards by passing in your own String arguments into the getResource() method:

     myList.addItem({label: LocaleManager.localeManager.getResource("full-name", "Mr.", "esq." )});
     

The arguments in the parameter list follow the order in which they appear in the resource String. The same wildcard can be specified more than once. The example above creates the following String:

     Mr. Westlee Barichuk esq.
     

View the examples

See also

Locale
LocaleManager


Public Properties
 PropertyDefined By
  loaded : Boolean
[read-only] Returns true if a property file has been loaded and parsed.
LocaleResourceBundle
Public Methods
 MethodDefined By
  
Creates an instance of a LocaleResourceBundle.
LocaleResourceBundle
  
getResource(key:String, ... args):String
Returns the value for the specified key from the loaded property file.
LocaleResourceBundle
  
load(path:String):void
Loads and parses a property file asynchronously given the path to the resource file.
LocaleResourceBundle
  
open(file:File):void
Loads and parses a property file given the path to the file.
LocaleResourceBundle
Events
 Event Summary Defined By
  Dispatched after a property file has been successfully loaded and parsed.LocaleResourceBundle
  Dispatched if the specified file to load cannot be found.LocaleResourceBundle
Property Detail
loadedproperty
loaded:Boolean  [read-only]

Returns true if a property file has been loaded and parsed.


Implementation
    public function get loaded():Boolean
Constructor Detail
LocaleResourceBundle()Constructor
public function LocaleResourceBundle()

Creates an instance of a LocaleResourceBundle.

Method Detail
getResource()method
public function getResource(key:String, ... args):String

Returns the value for the specified key from the loaded property file. If the key is not found in the bundle, the literal key value will be returned instead.

Parameters

key:String — The key for the value in the property file.
 
... args — Optional parameters that can be used as wildcard replacements in the returned String.

Returns
String — Returns the value for the specified key.
load()method 
public function load(path:String):void

Loads and parses a property file asynchronously given the path to the resource file. Because this is an asynchronous operation, you must wait for the resource bundle to load before you access it. An Event.COMPLETE event is fired after the file is loaded and parsed.

The following example shows a simple bundle load operation that creates and initializes a resource bundle. An event listener is added to the bundle to listen for the bundle load (Event.COMPLETE) event. The getLocalePath() method is used to specify the path to the resource bundle.

            //Load the resource bundle
            var MyBundle:LocaleResourceBundle = new LocaleResourceBundle();
            MyBundle.addEventListener( Event.COMPLETE, onResourceLoad );
            MyBundle.load(LocaleManager.getLocalePath() + "/resource.properties"); 
                
            myDP = new DataProvider();
            
        }
        
        //This function is called when the resource bundle is loaded. 
        private function onResourceLoad(event:Event):void 
        {
            
            trace(LocaleManager.localeManager.getCurrentLocale());
            //Store the incoming event target as a bundle.
            var bundle:LocaleResourceBundle = event.target as LocaleResourceBundle;
            
            //Update the buttons in the segmented control with the bundle resources
            myDP.setItems([{label: bundle.getResource("day-sunday")},
                           {label: bundle.getResource("day-monday")},
                           {label: bundle.getResource("day-tuesday")},
                           {label: bundle.getResource("day-wednesday")},
                           {label: bundle.getResource("day-thursday")},
                           {label: bundle.getResource("day-friday")},
                           {label: bundle.getResource("day-saturday")}]);
            
            
            mySegmented.dataProvider = myDP;
                            
        }
        

Parameters

path:String — The path to the resource file to be loaded.

See also

open()method 
public function open(file:File):void

Loads and parses a property file given the path to the file. This is a synchronous operation.

The following example shows a simple function that creates and opens a resource bundle. The applicationDirectory class and resolvePath() method are used to specify the location of the resource bundle. The applicationDirectory is used to specify the root application folder, and to pass a File object to the open method.

        public function bundleOpen():void
        {
            bundle = new LocaleResourceBundle();
            bundle.open( File.applicationDirectory.resolvePath( "locale/en_US/resource.properties" ) );        
        }
        

Parameters

file:File — The File object to open and parse.

See also

Event Detail
complete Event
Event Object Type: flash.events.Event
Event.type property = flash.events.Event.COMPLETE

Dispatched after a property file has been successfully loaded and parsed.

See also

ioError Event  
Event Object Type: flash.events.IOErrorEvent
IOErrorEvent.type property = flash.events.IOErrorEvent.IO_ERROR

Dispatched if the specified file to load cannot be found.

See also

Examples

In the following example, a LocaleResourceBundle class is instantiated and a resource file is loaded and parsed in order to populate a SegmentedControl instance.

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    import qnx.locale.LocaleManager;
    import qnx.locale.LocaleResourceBundle;
    import qnx.ui.buttons.SegmentedControl;
    import qnx.ui.data.DataProvider;
    [SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
    public class MyLocaleSample extends Sprite
    {
        
        private var mySegmented:SegmentedControl;
        private var myDP:DataProvider;
        
        public function MyLocaleSample()
        {
            initializeUI();
        }
        
        private function initializeUI():void
        {
            
            //Create a segmented control
            mySegmented = new SegmentedControl();
            mySegmented.setPosition(100, 500);            
            mySegmented.width = 750;
            mySegmented.height = 50;    
            stage.addChild(mySegmented);
            
            //Load the resource bundle
            var MyBundle:LocaleResourceBundle = new LocaleResourceBundle();
            MyBundle.addEventListener( Event.COMPLETE, onResourceLoad );
            MyBundle.load(LocaleManager.getLocalePath() + "/resource.properties"); 
            
            myDP = new DataProvider();
        
        }
        
        //This function is called when the resource bundle is loaded. 
        private function onResourceLoad(event:Event):void 
        {
            
            trace(LocaleManager.localeManager.getCurrentLocale());
            //Store the incoming event target as a bundle.
            var bundle:LocaleResourceBundle = event.target as LocaleResourceBundle;
                    
            //Update the buttons in the segmented control with the bundle resources
            myDP.setItems([{label: bundle.getResource("day-sunday")},
                           {label: bundle.getResource("day-monday")},
                           {label: bundle.getResource("day-tuesday")},
                           {label: bundle.getResource("day-wednesday")},
                           {label: bundle.getResource("day-thursday")},
                           {label: bundle.getResource("day-friday")},
                           {label: bundle.getResource("day-saturday")}]);
            
            
            mySegmented.dataProvider = myDP;
                            
        }
    
    }
}
     

The example above uses a resource file (resource.properties) which is located in the English language locale directory (locale/en_US). The file is listed below:

day-monday=Monday
day-tuesday=Tuesday
day-wednesday=Wednesday
day-thursday=Thursday
day-friday=Friday
day-saturday=Saturday
day-sunday=Sunday