Ext.js - 本地化
用用户理解和喜欢的语言与他们交流总是最好的。Extjs 本地化包支持 40 多种语言,例如德语、法语、韩语、中文等。在 ExtJs 中实现语言环境非常简单。您会在 ext-locale 包的 override 文件夹中找到所有捆绑的语言环境文件。语言环境文件只是告诉 Ext JS 替换某些组件的默认英语值的覆盖。
以下程序用于显示不同语言环境中的月份以查看效果。尝试以下程序。
<!DOCTYPE html> <html> <head> <link href = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" rel = "stylesheet" /> <script type = "text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/ext-all.js"></script> <script type = "text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-fr.js"></script> <script type = "text/javascript"> Ext.onReady(function() { var monthArray = Ext.Array.map(Ext.Date.monthNames, function (e) { return [e]; }); var ds = Ext.create('Ext.data.Store', { fields: ['month'], remoteSort: true, pageSize: 6, proxy: { type: 'memory', enablePaging: true, data: monthArray, reader: {type: 'array'} } }); Ext.create('Ext.grid.Panel', { renderTo: 'grid', id : 'gridId', width: 600, height: 200, title:'Month Browser', columns:[{ text: 'Month of the year', dataIndex: 'month', width: 300 }], store: ds, bbar: Ext.create('Ext.toolbar.Paging', { pageSize: 6, store: ds, displayInfo: true }) }); Ext.getCmp('gridId').getStore().load(); }); </script> </head> <body> <div id = "grid" /> </body> </html>
上述程序将产生以下结果
要使用除英语以外的其他语言环境,我们需要在程序中添加特定于语言环境的文件。这里我们使用 https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/localefr.js 表示法语。您可以为不同的语言使用不同的语言环境,例如 https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-ko.js 表示韩语等。
以下程序用于在韩语环境中显示日期选择器以查看效果。尝试以下程序。
<!DOCTYPE html> <html> <head> <link href = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" rel = "stylesheet" /> <script type = "text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/ext-all.js"></script> <script type = "text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-ko.js"></script> <script type = "text/javascript"> Ext.onReady(function() { Ext.create('Ext.picker.Date', { renderTo: 'datePicker' }); }); </script> </head> <body> <div id = "datePicker" /> </body> </html>
上述程序将产生以下结果 −
下表列出了 ExtJS 中可用的几个语言环境以及要更改的主文件语言环境 URL。
语言环境 | 语言 | 语言环境 URL |
---|---|---|
ko | 韩语 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-ko.js |
fr | 法语 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-fa.js |
es | 西班牙语 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-es.js |
ja | 日语 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-ja.js |
it | 意大利语 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-it.js |
ru | 俄语 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-ru.js |
zh_CN | 简体中文 | https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/localezh_CN.js |