Announcement Announcement Module
Collapse
No announcement yet.
Runtime ResourceBundle Loading Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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, 07:52 AM. Reason: added post scriptum

    Comment


    • #3
      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?

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment


          • #6
            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

            Comment


            • #7
              Done.

              https://jira.springframework.org/bro...ONSCRIPTAS-117

              Comment

              Working...
              X