Results 1 to 6 of 6

Thread: workspace singleton localisation

  1. #1
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    9
    Vote Rating
    0
      0  

    Default workspace singleton localisation

    My application has a template similar to the code below:

    Code:
    MyApp.workspace = function() {
        var viewport;
        //...
        return {
            init: function() {},
            //...
            destroy : function() {}
        }
    }();
    
    // bootstrap application
    Ext.onReady(MyApp.workspace.init, MyApp.workspace);
    All the pre-config components used in the application can be localised with use of language file. Is something similar possible with my application workspace?

    Something like this:

    Code:
    if(MyApp.workspace) {
        Ext.apply(MyApp.workspace.prototype, {
            textConfigVar    : 'localized content',
        });
    }
    Will such an approach work and where should i put the config vars ? Maybe inside the init funtion?

    --

    Jack

  2. #2
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,676
    Vote Rating
    9
      0  

    Default

    Code:
    MyApp.workspace = function() {
        var viewport;
        //...
        return {
            init: function() {}
            //... here you can localize
            destroy : function() {}
        }
    }(); // <- this makes it a singleton
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  3. #3
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    9
    Vote Rating
    0
      0  

    Default

    I can only get the inline (default) config var value in the components, but not the localized value defined in a language file.

    My code looks something like this:

    Code:
    MyApp.workspace = function() {
        var viewport;
        //...
        return {
            init: function() {},
            textConfigVar: 'default english',
            someBuildFunction: function() {
                return new Ext.Panel({
                   html: '<p>' + this.textConfigVar + '</p>'
                });
            },
            destroy : function() {}
        }
    }();
    To me it seems this does not work in a similar fashion as some pre-config component. What am i missing ? I could offcourse turn the panel in this case into a pre-config component and define config vars there, but am just wondering if it can be done in this mannor.

    --

    Jack

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,626
    Vote Rating
    54
      0  

    Default

    You are missing the fact that you are just creating an Object, not a class.

    MyApp.workspace is assigned to reference what is returned by that return statement. Which is just an object.
    Longtime Sencha geek. Outspoken advocate of pure Javascript Views. Posts my own opinions.

  5. #5
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,676
    Vote Rating
    9
      0  

    Default

    you could init a lang object like
    Code:
    MyApp.language = {
      label1: 'bla'
      label2: 'bla2'
    }
    and in your init you can override this object with users language. In your component you would use MyApp.language.label1 for example.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  6. #6
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    9
    Vote Rating
    0
      0  

    Default

    Object in seperate file with localized config vars seems to be a good solution.

    Code:
    return {
        textConfigVars: {
            var1 : 'default var 1',
            var2 : 'default var 2'
        },
        init: function() {
            //...
            this.textConfigVars = MyApp.language.textConfigVars;
            //...
        }
    }
    Code:
    MyApp.language = {
        textConfigVars: {
            var1 : 'localized var 1',
            var2 : 'localized var 2'
        }
    };
    This seems to be a fine solution for my 'problem'.

    Thanks for pointing me into the right direction.

    --

    Jack

Similar Threads

  1. Singleton Pattern
    By plalx in forum Ext 3.x: User Extensions and Plugins
    Replies: 0
    Last Post: 18 Apr 2010, 7:09 AM
  2. Singleton object
    By asagala in forum Ext 3.x: Help & Discussion
    Replies: 9
    Last Post: 7 Oct 2009, 6:30 AM
  3. A Logger singleton
    By Animal in forum Ext 2.x: User Extensions and Plugins
    Replies: 2
    Last Post: 19 Nov 2007, 7:38 AM
  4. Workspace - Web based IDE
    By jguru in forum Community Discussion
    Replies: 1
    Last Post: 20 Jul 2007, 10:55 AM
  5. Your Workspace
    By jon.whitcraft in forum Community Discussion
    Replies: 6
    Last Post: 20 Jun 2007, 6:47 AM

Posting Permissions

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