Results 1 to 7 of 7

Thread: Runtime ResourceBundle Loading

  1. #1

    Cool Runtime ResourceBundle Loading

    I remember a while back that in the documentation, it mentioned a way to create runtime resource bundles in Spring AS. I'd really like to be able to do this but I can't seem to find anything in the current documentation about it. I'd basically like to load property files at runtime into the resource bundle like so: "resources.en-US.properties".

    I'm aware of the localization aware stage processor, but I really want to do this using resource bundles. Does anyone know how I would go about it or where I'd find it in the documentation?

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default standard Flex functionality

    Hey there,

    what you want to do doesn't necessarily need Spring AS, you can very easily do this by loading your property file, reading it line by line and extracting the name/value pairs and then construct a run-time resourcebundle like this:

    Code:
    var rb:ResourceBundle = new ResourceBundle();
    rb.bundleName "myResources";
    rb.locale = "us_US";
    rb.content["mykey"] = "myvalue";
    //etc...
    P.S. Maybe this functionality could be implemented in Spring Actionscript as a standard resource loader. I'll see what I can do.

    finally you can add this bundle to the ResourceManager instance like this:

    Code:
    ResourceManager.getInstance().addResourceBundle(rb);
    cheers,

    Roland

    P.S. Maybe this functionality can be added to Spring AS as a standard Resource loader, I'll see what I can do.
    Last edited by 666shooter; Oct 19th, 2010 at 06:52 AM. Reason: added post scriptum

  3. #3

    Default

    Hmm, I thought I had remembered some sort of short way of doing this.

    Something like the following:

    Code:
    <r:resource-bundle name="resources">
        <r:language name="en_US" file="resources.en_US.properties"/>
    </r:resource-bundle>
    Perhaps I'm remembering what I _want_ to remember, though

    I'd be happy to develop a plugin for this though. I'm sure that I'm not the only one who would like to externalize (not hard-code) all of my i18n in Flex. Is there a way to do the above "the long way," but having Spring AS load my properties files into key-value pairs BEFORE the application context dispatches Event.COMPLETE?

  4. #4
    Join Date
    Oct 2008
    Location
    Belgium
    Posts
    160

    Default

    Hi,

    If you are using the FlexXMLApplicationContext, there is a addResourceBundleLocation() method that enables you to load external properties files that will be parsed into resource bundles.

    regards,
    Christophe
    Christophe Herreman
    Spring ActionScript Founder
    http://www.herrodius.com

  5. #5

    Default

    I think that just about solves my problem

    Is there any way to do this same thing from within an application context XML? If not, no worries, I'll just pass in an array of flashvars to my application as so:

    Code:
    { 
        'resources': [
            { 'name': "English (US)", 'locale': "en_US", 'file': "i18n/resources.en_US.properties" },
            { 'name': "English (UK)", 'locale': "en_GB", 'file': "i18n/resources.en_GB.properties" }
        ] 
    }
    My main goal here is to keep resource bundles completely external from the application itself.

  6. #6
    Join Date
    Oct 2008
    Location
    Belgium
    Posts
    160

    Default

    Hi,

    that sounds like a valid use-case. We recently added support to the container to load extra resources before its complete event is dispatched. This opens the door to all sorts of extra (asynchronous) setup and loading resource bundles is certainly part of that.

    Please create a Jira issue for this and we'll have a look at it.

    regards,
    Christophe
    Christophe Herreman
    Spring ActionScript Founder
    http://www.herrodius.com

  7. #7

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •