Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    6
    Vote Rating
    0
    gregweber is on a distinguished road

      0  

    Default applyTitle lazily for keeping translated titles in config

    applyTitle lazily for keeping translated titles in config


    I have a patch for a very small feature. This is the only place I could find to report it (reporting this would be an order of magnitude easier if the releases were mirrored to github!)

    This patch allows me to write code like the following in a view:

    Code:
    config: {
          items: [
            {
              xtype: 'fieldset',
              itemId: 'fsetproviders',
              title: function() { return _('providers'); },
              hidden: true
          }
    ] }
    I noticed that once translations were needed, information needed to be put into the ititialize function of a view with 'this.add' to delay evalulation of the translation function. This patch lets me keep more in the config. A javascript user needs to add the 'function(){return }' boilerplate to take advantage, but using coffeescript means I only need add 2 characters for an arrow.

    Code:
        allow functions in addition to strings
        
        This delays the evaluation of the string.
        _() translations can now be used in the config if wrapped in a function
    
    
    --- a/src/MessageBox.js
    +++ b/src/MessageBox.js
    @@ -204,6 +204,8 @@ Ext.define('Ext.MessageBox', {
                 config = {
                     title: config
                 };
    +        } else if (typeof title == 'function') {
    +          return this.applyTitle(title());
             }
     
             Ext.applyIf(config, {
    --- a/src/Toolbar.js
    +++ b/src/Toolbar.js
    @@ -186,6 +186,8 @@ Ext.define('Ext.Toolbar', {
                     title: title,
                     centered: true
                 };
    +        } else if (typeof title == 'function') {
    +          return this.applyTitle(title());
             }
     
             return Ext.factory(title, Ext.Title, this.getTitle());
    --- a/src/form/FieldSet.js
    +++ b/src/form/FieldSet.js
    @@ -65,6 +65,8 @@ Ext.define('Ext.form.FieldSet', {
         applyTitle: function(title) {
             if (typeof title == 'string') {
                 title = {title: title};
    +        } else if (typeof title == 'function') {
    +          return this.applyTitle(title());
             }
     
             Ext.applyIf(title, {
    --- a/src/picker/Slot.js
    +++ b/src/picker/Slot.js
    @@ -153,6 +153,8 @@ Ext.define('Ext.picker.Slot', {
                     docked      : 'top',
                     html        : title
                 });
    +        } else if (typeof title == 'function') {
    +          return this.applyTitle(title());
             }
     
             return title;
    Thanks,
    Greg Weber

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,219
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Your method of translation needs to accomodate the title receiving a string. This seems more application/extension specific.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    6
    Vote Rating
    0
    gregweber is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Your method of translation needs to accomodate the title receiving a string.
    You can't see the surrounding code in the patch, but this is just an addition to the normal string.

    Quote Originally Posted by mitchellsimoens View Post
    This seems more application/extension specific.
    This could apply to anyone that uses internationalization in their views.


    Is this the right place to send this? This forum was suggested to me by a Sencha employee, but I am not sure if it is getting through to developers of the framework.

    Best,
    Greg Weber

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,219
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This is the right place (and I am a dev that works for Sencha) but we need to discus if it does belong within the framework or if it is more app/extension behavior. Currently there is no locale handling in the framework.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    6
    Vote Rating
    0
    gregweber is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    This is the right place (and I am a dev that works for Sencha) but we need to discus if it does belong within the framework or if it is more app/extension behavior. Currently there is no locale handling in the framework.
    oh, well maybe it doesn't then. Obviously this works for other things than just locale, but I have not encountered those use cases myself yet. If you think it is better as an extension, can you give me a pointer on how I can create this behavior as an extension?

  6. #6
    Sencha User
    Join Date
    May 2012
    Posts
    6
    Vote Rating
    0
    gregweber is on a distinguished road

      0  

    Default


    Actually, what I really want is lazy evaluation of the config (let the config property be a function that returns a config). This is useful beyond internationalization: anything being placed in the initialize function for later evaluation (setting a store instance with overrides for example) can now be placed directly in the config. Unfortunately I don't know how to override how the config is handled. Any pointers would be appreciated.

Thread Participants: 1