2011-10-27 65 views
0

我紧随本地化指南:http://docs.sencha.com/ext-js/4-0/#!/guide/localization,但我无法使其在MVC模式下工作。 我不需要像前面的例子那样进行动态定位,我只是想在应用程序加载时设置它。ExtJS 4.0:本地化问题

我想是这样的:

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调用,则不会收到任何错误,但不会应用翻译。

回答

0

它将在生产模式下工作,所有ext JavaScript文件都在应用程序启动之前加载。我也有这个问题。试着做这个测试:导入'ext-all.js'文件,然后导入你的语言文件。这将工作。不是最好的解决方案,但是我发现这是唯一的解决方案。

您的问题的原因:

如果你打开你的翻译文件,你会发现这样的指令:

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

如果文件“Ext.view.View.js”未装载在你加载你的翻译文件的时候,你会得到一个错误,因为'Ext.view.View'类不存在。

我希望任何人都可以帮助您提供更好的解决方案。

+0

工程,但正如你所说,它不是最优雅的解决方案。 – Milan

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

+0

这不起作用,因为本地化会逐一请求所有其他组件:网格,表单域,选取器等。 – Milan

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