Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    2
    Vote Rating
    0
    x_lilu_x is on a distinguished road

      0  

    Default Solution for Localisation with MVC and dynamic loading in ExtJS4.1

    Solution for Localisation with MVC and dynamic loading in ExtJS4.1


    In the last days, i searched desperated for a way to enable localisation in combination with MVC and dynamic loading. I found two solutions which were not really comfortable and finally i implemented a way by myself. Because it seems, that many people search a solution for this problem, i will post my way here.

    First, i defined a own base controller for my app which has a slightly changed "onClassExtended" method.
    Code:
    Ext.define('dnes.app.Controller', {
        extend: 'Ext.app.Controller',
        onClassExtended: function(cls, data, hooks) {
        var className = Ext.getClassName(cls),
        match = className.match(/^(.*)\.controller\./),
        namespace,
        onBeforeClassCreated,
        requires,
        modules,
        namespaceAndModule;
            
        if (match !== null) {
            namespace = Ext.Loader.getPrefix(className) || match[1];
            onBeforeClassCreated = hooks.onBeforeCreated;
            requires = [];
            modules = ['model', 'view', 'store', 'locale'];
    
    
            hooks.onBeforeCreated = function(cls, data) {
            var i, ln, module,
            items, j, subLn, item;
            
            for (i = 0,ln = modules.length; i < ln; i++) {
                module = modules[i];
                namespaceAndModule = namespace + '.' + module + '.';
    
    
                items = Ext.Array.from(data[module + 's']);
    
    
                for (j = 0,subLn = items.length; j < subLn; j++) {
                item = items[j];
                // Deciding if a class name must be qualified:
                // 1 - if the name doesn't contains at least one dot, we must definitely qualify it
                // 2 - the name may be a qualified name of a known class, but:
                // 2.1 - in runtime, the loader may not know the class - specially in production - so we must check the class manager
                // 2.2 - in build time, the class manager may not know the class, but the loader does, so we check the second one
                //       (the loader check assures it's really a class, and not a namespace, so we can have 'Books.controller.Books',
                //       and requesting a controller called Books will not be underqualified)
                if (item.indexOf('.') !== -1 && (Ext.ClassManager.isCreated(item) || Ext.Loader.isAClassNameWithAKnownPrefix(item))) {
                    requires.push(item);
                } else {
                    if(module == 'locale' && typeof document._application_language != 'undefined') {
                    requires.push(namespaceAndModule + item + '.' + document._application_language);
                    } else {
                    requires.push(namespaceAndModule + item);
                    }
                }
                }
            }
    
    
            Ext.require(requires, Ext.Function.pass(onBeforeClassCreated, arguments, this));
            };
        }
        }
    });
    Now all my controllers extend this new base controller, what gives me the possibility to define "locales" which is an array with the language files, i want to load.
    Code:
    Ext.define('dnes.controller.user.User', {
        extend: 'dnes.app.Controller',
        views: ['user.Register'],
        locales: ['user.Register'],
        onLaunch: function(app) {
        ...
        }
    });
    Then i just need to put the language files in the right directory. For the example above, this would be "locale/user/Register/". The name of the language files have to be the name of the language they define. For english it would be "en.js"
    Code:
    Ext.define('dnes.locale.user.Register.en', {
        override: 'dnes.view.user.Register',
        title: 'Register new user',
        account: {
        label: 'Account data',
        username: 'Username',
        usermail: 'Email',
        password: 'Password'
        }
    });
    As you can see, each language file defines a class fitting to its path and overrides the class which uses the language definitions. The view in this case looks as following.
    Code:
    Ext.define('dnes.view.user.Register', {
        ...
        initComponent: function() {
        var me = this;
        
        me.items = [{
            xtype: 'fieldset',
            defaultType: 'textfield',
            title: me.account.label,
            items: [{
            fieldLabel: me.account.username,
            name: 'user_name',
            allowBlank: false
            }, {
            fieldLabel: me.account.usermail,
            name: 'user_mail',
            allowBlank: false 
            }, {
            fieldLabel: me.account.password,
            name: 'user_pass',
            allowBlank: false,
            inputType: 'password'
            }]
        }];
        
        me.callParent();
        }
    });
    At last i just need to define the language code for the language, i want to load. That can be done by a specialised function or in a script tag on page load. All what have to happen is, that anywhere before your application, you define document._application_language = 'en'; where you relace 'en' by the language code, you want to load. Now the ClassLoader load the defined "locales" as requires after all other components like stores, models and views are loaded but before the views are rendered.

    I hope, this solution helps anybody and you like it.

    Lilu

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,520
    Vote Rating
    814
    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


    So you have to load many files, 1 per view? Sounds expensive.
    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
    Apr 2010
    Location
    Philippines
    Posts
    2
    Vote Rating
    0
    x_lilu_x is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    So you have to load many files, 1 per view? Sounds expensive.
    I'm not sure, if it's necessary to load one language file for every view. That approach is just the point i worked out 'til now. Maybe it's possible just to register one language file per controller and define a wrapper class in it, which holds all the definitions for all the views of the controller. The views just get the definitions from the wrapper class then.

    I also found your solution with the LocaleManager but it's a little to much for my needs. As far as i understand it, your manager makes it possible to change the language on the fly but i have to override all the standard components in Ext to get it work, right? I'm a little concerned about the the amount of work to maintain that all. Especially when it comes to updates in the codebase.

Thread Participants: 1

Tags for this Thread