3 Replies Latest reply on Nov 19, 2011 5:10 PM by drkstr_1

    trying to implement getText style shortcut for RM.getString() - need help!!!

    cosmits Level 1

      Hi all

      I'm working on a flex app that is using ResourceManager for localization

      I've set up all the locales, properties files, ant script and all is running fine

      I find it a bit redundent to write this for every string in the entire app -  resourceManager.getString('myBundle','SOME_KEY')

      so I've tried to come up with a cleaner way to encapsulate this repetative task.

      instead of implementing a singleton, I simply wrote a global function in the getText style:

       

      so the function usage would simply be:     _('SOME_KEY')

      nice right?

       

      the function implementation:

       

      package

      {

                import mx.resources.IResourceManager;

                import mx.resources.ResourceManager;

       

                [Bindable("change")]

                public function _(key:String,bundle:String='myBundle'):String{

                 return ResourceManager.getInstance().getString(bundle,key);

                }

      }

       

      the problem is that this works fine:

      <s:Label  text="{ resourceManager.getString('myBundle','SOME_KEY') }" />

       

      but this doesn't:

      <s:Label  text="{  _('SOME_KEY')}" />

       

      using the debugger I can noticed the function is called the first time before the resource bundle is ready

      after the resourcemanager had finished loading the resource bundle modules, this function is not being called for some reason

      so I figured it has to do with the binding

      I made sure I'm using the same exact bindable event metadata tag as the getString method use on IResourceManager

      but it still doesn't get updated

      any reason for that

      do you see anything else I can do to make it work?

      thanks

      Yariv