ExtJS 4.0:本地化问题

时间:2011-10-27 13:16:43

标签: extjs localization extjs4

我密切关注本地化指南:http://docs.sencha.com/ext-js/4-0/#!/guide/localization,但我不能让它在MVC模式下工作。 我不像前面的例子那样需要动态本地化,我只想在应用程序加载时设置它。

我试过这样:

Ext.application({
name: 'KS',

appFolder: 'app',

controllers: ['Menu', 'DailyReport', 'DP'],

launch: function() {
    Ext.Ajax.request({
        url: 'lib/ext-4.0/locale/ext-lang-es.js',
        success: function(response, opts) {
            eval(response.responseText);
        },
        failure: function() {
            Ext.Msg.alert('Error', 'Error al cargar archivos de idioma.');
        }
    });
    Ext.create('Ext.container.Viewport', {
        items: [{
            xtype: 'menu'
        },
        {
            xtype: 'dpedit'
        }]
    });

}
});

在萤火虫中我得到:“Ext.view未定义”错误,没有任何渲染。如果我在创建Viewport后尝试Ajax调用,我不会收到任何错误,但不会应用转换。

3 个答案:

答案 0 :(得分:1)

更优雅的解决方案是让自动加载器在运行启动方法之前加载类。 您可以根据需要定义Ext.view.View来执行此操作:

Ext.application({
    name: 'KS',

    appFolder: 'app',

    controllers: ['Menu', 'DailyReport', 'DP'],

    // This will make shure the class is loaded before your application runs:
    requires : ['Ext.view.View'],

    launch: function() {
        Ext.Ajax.request({
            url: 'lib/ext-4.0/locale/ext-lang-es.js',
            success: function(response, opts) {
                eval(response.responseText);
            },
            failure: function() {
                Ext.Msg.alert('Error', 'Error al cargar archivos de idioma.');
            }
        });
        Ext.create('Ext.container.Viewport', {
            items: [{
                xtype: 'menu'
            },
            {
                xtype: 'dpedit'
            }]
        });
    }
});

有关详细信息,请参阅extjs api

答案 1 :(得分:0)

在应用程序启动之前加载所有ext javascript文件时,它将在生产模式下工作。我也有这个问题。尝试执行此操作以测试:导入'ext-all.js'文件,然后导入语言文件。这会奏效。不是最好的解决方案,但是我发现的唯一解决方案。

问题的原因:

如果您打开翻译文件,您会注意到这样的指令:

Ext.view.View.prototype.emptyText = "";

如果在加载翻译文件时没有加载文件'Ext.view.View.js',则会出现错误,因为'Ext.view.View'类不存在

我希望有人可以帮助你找到更好的解决方案。

答案 2 :(得分:0)

我很容易解决这个问题。它很简单,效果会更好。将它放在你的文档头中,在ext.js / ext-all.js之后,在你的app.js之前。 (我根据本地化指南把它放在language.js的底部)

var params = Ext.urlDecode(window.location.search.substring(1));
if (params.lang) {
  var url = Ext.util.Format.format('/assets/extjs/locale/ext-lang-{0}.js', params.lang);
  document.write("<script src='" + url + "'><\/script>");
}

我正在使用/ assets来使用rails 3.1。

这有助于查询参数中的?lang = fr,应用程序的其余部分应该按照指南工作。

http://docs.sencha.com/ext-js/4-0/#!/guide/localization