EXTJS4.x之国际化

extjs工程实现国际化支持,但是在Sencha Architect 里面我还没找到实现方法,所以只能在源码上来实现了,下面我们来实现一个国际化的例子:

使用Sencha Architect 创建localization工程,保存到webroot目录下,并制作以下界面


保存并运行一下


可以看到现在是英文的

下面我们关闭Sencha Architect,在myeclipse中直接编辑代码。

修改app.html文件,内容如下

<!DOCTYPE html>

<!-- Auto Generated with Sencha Architect -->
<!-- Modifications to this file will be overwritten. -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Localization</title>
    <script src="http://extjs.cachefly.net/ext-4.1.1-gpl/ext-all.js"></script>
    <link rel="stylesheet" href="http://extjs.cachefly.net/ext-4.1.1-gpl/resources/css/ext-all.css">
    <!-- Include the translations -->
    <script type="text/javascript" src="ext-lang-zh_CN.js"></script>
    <script type="text/javascript" src="app.js?_dc=1368864811298"></script>
</head>
<body></body>
</html>

导入 ext- lang-zh_CN.js文件,这个是中文文件,以此类推需要多个个语言就要多少个类似的文件

ext-lang-zh_CN.js的内容如下

var myProject = {};
myProject.string = {};
myProject.string.title = '我的表单';
myProject.string.lable = '本地化';

然后修改MyForm.js内容如下

/*
 * File: app/view/MyForm.js
 *
 * This file was generated by Sencha Architect version 2.1.0.
 * http://www.sencha.com/products/architect/
 *
 * This file requires use of the Ext JS 4.1.x library, under independent license.
 * License of Sencha Architect does not include license for Ext JS 4.1.x. For more
 * details see http://www.sencha.com/license or contact license@sencha.com.
 *
 * This file will be auto-generated each and everytime you save your project.
 *
 * Do NOT hand edit this file.
 */

Ext.define('MyApp.view.MyForm', {
    extend: 'Ext.form.Panel',

    height: 250,
    width: 400,
    bodyPadding: 10,
    title: myProject.string.title,

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'label',
                    text: myProject.string.lable
                }
            ]
        });

        me.callParent(arguments);
    }

});

保存运行可以看到


同样我们创建一个ext-lang-es.js内容如下

var myProject = {};
myProject.string = {};
myProject.string.title = 'My From';
myProject.string.lable = 'Localization';
在app.html中改为导入 ext- lang-es.js。保存运行



最后只需要根据不同的语言需求动态加载不同的语言包即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值