1

私のアプリケーションでは、すべてのコンポーネントのタイトル/テキストは、アプリケーションの起動前にロードされたストアに基づいてローカライズされています。アプリケーションには、ストアのURLを変更し、ストアをリロードして言語を切り替えるボタンがあります。問題は、すべてのクラスがすでにロードされているため、コンポーネントが以前のロケールでレンダリングされることです。ボタンのコードは次のとおりです。

tbar: [{
    xtype: 'button',
    id: 'btn-test',
    text: 'xxx',
    handler: function() {
        lang = 'en';        
        i18n.getBundlestore().load({url:'/GSIP/resources/gsip/i18n/bundle-' + lang + '.properties'});

        //bun = Ext.create('I18N.ResourceBundle'); 

        Ext.getCmp('mainview').destroy();

        Ext.create('Ext.container.Viewport', {
            id: 'mainview',
            layout: 'border',
            items: [
                {
                 xtype: 'gsip_mainpanel',
                 region: 'center',
                 items: [{
                     xtype: 'gsip_categoriestabpanel'
                 }]

                }
            ] 

まったく同じビューポートの作成が私のApplication.jsにあります。langとi18nはグローバル変数です。古いビューポートは破棄され、新しいビューポートが作成されますが、クラスを強制的に再ロードする方法。window.locationを使用したくありません。

更新されたコード:

handler: function() {

        lang = 'en';        

        Ext.getCmp('mainview').destroy();

        i18n.getBundlestore().load({url:'/GSIP/resources/gsip/i18n/bundle-' + lang + '.properties',
            callback: function() {
                Ext.create('Ext.container.Viewport', {
                    id: 'mainview',
                    layout: 'border',
                    items: [
                        {
                         xtype: 'gsip_mainpanel',
                         region: 'center',
                         items: [{
                             xtype: 'gsip_categoriestabpanel'
                         }]

                        }
                    ]            
                });
            }
        });

    }

カテゴリTabPanel:

Ext.define('GSIP.view.CategoriesTabPanel' ,{
extend: 'Ext.tab.Panel',
alias : 'widget.gsip_categoriestabpanel',   
layout: 'fit',
items: [{
    xtype: 'gsip_planytabpanel',
    title: i18n.getMsg('key-1')
},{
    xtype: 'gsip_adresytabpanel',
    title: i18n.getMsg('key-2')
}],
initComponent: function() {

    this.callParent(arguments);

}

});

およびResourceBundle(i18n変数はこのクラスのインスタンスです):


Ext.define('I18N.ResourceModel',{

        extend: 'Ext.data.Model',
        fields: ['key', 'value']
    });

    Ext.define('I18N.ResourceStore',{
        extend: 'GSIP.core.RegisteredStore',
        model: 'I18N.ResourceModel',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: '/GSIP/resources/gsip/i18n/bundle-' + lang + '.properties',
            reader: {
                type: 'json',
                root: 'pl',
                successProperty: 'success'
            }
        }
    });

    Ext.define('I18N.ResourceBundle' ,{

        config: {
            bundlestore: Ext.create('I18N.ResourceStore'),
        },
        constructor: function(config) {
            this.initConfig(config);

            return this;
        },
        getMsg: function(key) {

            return this.bundlestore.getAt(this.bundlestore.findExact('key', key)).get('value');

        }
        },function(){
            //callback function, called before store load :(
        }
    );

4

1 に答える 1

1

widget.gsip_categoriestabpanelの定義内で、アイテムを構成として設定します。これは、常に同じオブジェクトを参照することを意味します(更新されたオブジェクトは参照しません)。最初のステップとして、アイテム定義をinitComponentに移動する必要があります。そこで、console.log(i18n)を使用して、それが正しいものであることを確認することもできます。

于 2012-07-10T12:21:56.517 に答える