1. #11
    Sencha User
    Join Date
    Sep 2009
    Posts
    2
    Vote Rating
    0
    boby1863 is on a distinguished road

      0  

    Default I have a problem ,please..

    I have a problem ,please..


    When I copy the example to my application,I found error:'meta.root' is null or is not an object, what problem with it?thanks.

  2. #12
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    67
    Vote Rating
    1
    elmasse is on a distinguished road

      0  

    Default


    boby1863 what version of ExtJS are you using? meta is an object created in the contructor of PropertyReader which extends form DataReader. And this is the component which uses the meta object. I have tested the latest version (0.2) with ExtJS 2.x and 3. Maybe you have a wrong version of Bundle Component.

    Please let me know, and do not hesitate to contact me directly.

    Regards

  3. #13
    Ext User
    Join Date
    May 2007
    Location
    France
    Posts
    30
    Vote Rating
    0
    Flukey is on a distinguished road

      0  

    Default


    Hi elmasse,

    Firstly, thank you for all the hard work you've put into this. :-)

    However, there are a couple of problems I have with using this plugin.

    You can't pass parameters into the bundle messages.

    For example, in my resources bundle I could have:

    Code:
    panel.title 'Welcome, %name%. You are signed as an %permission%'
    And then it would be nice to do:

    Code:
    panel.title = Bundle.getMsg("panel.title", { name: 'Flukey', permission: 'administrator' });
    So, the getMsg method would have some sort of sprintf functionality in it.

    Now that would be SO very helpful!

    What do you think? :-)

    Cheers!

  4. #14
    Ext User
    Join Date
    May 2007
    Location
    France
    Posts
    30
    Vote Rating
    0
    Flukey is on a distinguished road

      0  

    Default


    I made a couple of changes to the getMsg method to do as described above.

    Bundle.js:

    Code:
     
    	getMsg: function(key, params){
    		if(this.getById(key)){
    			this.message = Ext.util.Format.htmlDecode(this.getById(key).data);
    			if(params == null){
    				// no params
    				return this.message;
    			} else {
    				// has params. add parameter values to message
    				for (p in params) {
    					this.message = this.message.replace("%" + p + "%", params[p]);
    				} 
    				return this.message;
    			}
    		} else {
    			return key + 'undefined';
    		}
    	}
    And in the resource bundle I have:

    Code:
    alert.title 'Hello, %name%. You are logged in as an %permission%'
    alert.html 'Nice to see you again.'
    Example usage:

    Code:
    Ext.MessageBox.show({
    	title:  bundle.getMsg('alert.title', { name: 'Flukey', permission: 'administrator' }),
    	msg: bundle.getMsg('alert.html'),
            buttons: Ext.MessageBox.OK
    });
    And so the result would be 'Hello, Flukey. You are logged in as an adminstrator.'

    Let me know what you think. I am *sure* that code can be improved!

  5. #15
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,963
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default


    @Flukey--

    FYI: Ext enhances the String object to simulate sprintf:

    Code:
    String.format( 'Hello, {0}. You are logged in as an {1}. If you are not {0}, get out!' ,
     'Flukey', 'administrator' );
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  6. #16
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    67
    Vote Rating
    1
    elmasse is on a distinguished road

      0  

    Default


    @Flukey: Sorry for the delay but I'm in favor of what hendricd says, you can use the enhancements provided by ExtJS on String object. I will update my blog to post a very simple example. The very first idea of this plugin was to keep the same .properties files I have been using in Java, and this formating was done by Ext so I didn't need to add anything else.

    Thanks for the feedback !!!!!!!!!!

  7. #17
    Ext User
    Join Date
    May 2007
    Location
    France
    Posts
    30
    Vote Rating
    0
    Flukey is on a distinguished road

      0  

    Default


    @Hendricd, elmasse:

    I agree that using the ExtJS string object is a good idea but there is a reason I didn't use it.

    Let's say for example,you had a long string to translate.

    i.e.
    Code:
    "Welcome, :surname: , :forename:. You have been logged in for :time_logged_in: minutes. You are only allowed logged in for a total of :total_allowed_time: minutes. The time now is :user_locale_time:."
    That's easier to read....but if I format the string so I have use the String.format method of ExtJS it would be this (obviously):

    Code:
     "Welcome, {0} , {1} You have been logged in for {2} minutes. You are only allowed logged in for a total of {3} minutes. The time now is {4}"
    And therefore i'd do this to format it:
    Code:
    String.format(msg,  'BLOGGS', 'Joe', '120', '300', '1130am');

    I think the first example is easier to do as I know exactly what parameters to send through. {0} is not very descriptive - we only know what to put there because of the context but it's not completely obvious on first glance. And when overviewing a .properties file it's easier to see :forename:, urname: etc.

    Just my opinion :-)

  8. #18
    Sencha User realjax's Avatar
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    412
    Vote Rating
    6
    realjax is on a distinguished road

      0  

    Default


    Nice! thanks for that.

    note: Keep in mind that using a POST to get the .properties file may lead to 405 errors on IIS webservers

    Better change it to a GET if you have no specific reason to use a POST (and *I* can't think of a single one)

  9. #19
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    67
    Vote Rating
    1
    elmasse is on a distinguished road

      0  

    Default


    @Flukey: I would recommend you to override the format method as follows:

    String.format = function(format){
    var args = Ext.toArray(arguments, 1);

    obj = (args.length == 1 && Ext.isObject(args[0])) ? args[0] : args;
    return format.replace(/\{(\w+)\}/g, function(m, i){
    return obj[i];
    });
    }

    So in this way we can keep backwards compatibility and also add your idea to current format functionality.


    alert(String.format("Param 1: {0}, Param 2: {1}","par1", "par2"));
    alert(String.format("Param 1: {par1}, Param 2: {par2}",{par1:"par1", par2:"par2"}));

    @Hendricd: what do you think?

  10. #20
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    67
    Vote Rating
    1
    elmasse is on a distinguished road

      0  

    Default


    Quote Originally Posted by realjax View Post
    Nice! thanks for that.

    note: Keep in mind that using a POST to get the .properties file may lead to 405 errors on IIS webservers

    Better change it to a GET if you have no specific reason to use a POST (and *I* can't think of a single one)
    I have been asked about that, it is OK to me, I just used POST with no real reason but not exposing any parameter in URL.