ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:422.94KB ,
资源ID:18730533      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/18730533.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Sencha Ext JS 国际化和本地化Word格式文档下载.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Sencha Ext JS 国际化和本地化Word格式文档下载.docx

1、My english title);这样,应用程序的任何地方都能访问译文了,怎样访问呢?就像打字一样简单:Jnesis.Labels.button 或 Jnesis.Labels.title 这样做比”重写”类的方法优点在于本地化的值在一个文件里且容易使用,因为像上面看到的那样,每个元素是一个变量.一旦做到这一点,我们选择其他语言后只需要”重写”覆盖这个语言文件.有两个步骤:1. 从web服务加载数据,服务器响应回的JSON看起来像这样: button:Mon BoutontitleMon titre我们需要解析数据并用解析到的值覆盖我们默认的本地化单例类:Ext.define (Jnesis

2、.Application launch: function () Ext.Ajax.request( url:get-localization params:locale:fr, callback: function (options, success, response) var data = Ext.decode(response.responseText, true); Ext.override(Jnesis.Labels, data); Ext.create(Jnesis.view.main.Main); );加载重写的Ext JS类:Jnesis.locale.fr.Labels o

3、verride:Mon BoutonMon titre然后用Ext.Loader.loadscript 方法处理它,当它完成后加载我们的主视图: var lang = url = resources/locale/+lang+/Labels.js; Ext.Loader.loadScript( url, onLoad: function (options) 然后,我们希望通过在component基类里定义一个新的属性(例如:”localized”),使用我们擅长的原生继承机制获取到翻译类属性.这个属性可以是由键,值组成的简单JavaScript对象(记住上面的Jnesis.Labels.but

4、ton 和 Jnesis.Labels.title).用定义键的字符串,就可以获取到对象的值: extend:Ext.panel.Panel localized: Jnesis.Labels.title , buttons: text:Jnesis.Labels.button handler:onClickButton 一旦做到这一点,我们只需要重写”initComponent”的基类方法并将键的字符串转换为对象的值,那么我们就可以在任意Ext JS组件里使用了:overrides.localized.ComponentExt.Component initComponent: function

5、() var me = this, localized = me.localized, value; if (Ext.isObject(localized) for (var prop in localized) value = localizedprop; if (value) meprop = eval(value); me.callParent(arguments);此解决方案以透明的方式在任何层级的组件声明(Container 配置或 item 配置)正常运行.我的解决方案综合官方方案、Saki博客和Sencha论坛网友提供的方法,再根据自身项目的修改,形成自己的解决方案.项目介绍前端

6、全部采用Ext Js开发的单页面Desktop应用程序,也就是使用了Ext Js里的Desktop组件加以修改.使用Sencha Cmd进行构建.后端采用Java spring MVC修改需求:现需要将中文版加入英文版功能,并且可以随浏览器语言来识别显示中文版还是英文版,并且可以由用户自行修改语言,并记住语言.需求分析:其实就是要做国际化和本地化,但后端和前端都有需要做国际化地方,所以统一由server端管理获取语言:当打开应用时浏览器通过js查询本地cookie并获取,设置语言:当用户点击指定语言,发送请求到server修改cookies里的语言并响应回由浏览器接收显示server端国际化由

7、spring mvc完成前端国际化分为两部分A. 为项目内容的国际化,如产品,客户,用户登录等.B. 为Ext JS自身组件的国际化,例如必填字段提示文字,grid列头选择标题字等.实现A的方案要想实现A,参考官方的方案即可,且可以做到无刷新更换语言.因为官方的方案是只写了一个类,另一种语言需要从后端请求JSON覆盖JS类的方法来实现,不够统一,我将其修改为以下方法:定义一个单例的翻译类Locale,加入了多语言属性:VSMS.Locale lang:zh_CN username: zh_CN:用户名 en:Username inputusername:输入用户名Input username

8、login:登录Login forgotpassword:忘记密码Forgot password logout:注销Logout Dywexit:确定要退出吗?Exit? password:密码Password inputpassword:输入密码Input password checkcode:验证码Check code changeone:换一张Change autologin:自动登录Auto login)Application初始化时初始化VSMS.Locale.lang:VSMS.ApplicationExt.app.Application name:VSMS stores: / T

9、ODO: add global / shared stores here , /获取cookie 本地化语言 var lang = Ext.util.Cookies.get(lang if(!lang) lang = VSMS.Locale.lang = lang;在Sencha Cmd项目里的overrides新建目录localized,并重写Component的initComponent方法: meprop = eval(value)VSMS.Locale.lang;/根据不同语言来获取不同属性的值在view上使用localized属性包住需要翻译的属性,完整的view太长,下面显示了一个

10、片段:items: xtype:textfieldusername fieldLabel:VSMS.Locale.username, /用户名 emptyText:VSMS.Locale.inputusername /输入用户名 fieldCls:logininput beforeBodyEl:/i enableKeyEvents: true那么在viewController里如何使用翻译属性呢?参照下面的写法:VSMS.Locale.changeoneVSMS.Locale.lang到现在,所有A部分的国际化完成了.实现B的方案我们知道,在用Sencha Cmd构建不同语言应用程序时需要在项

11、目根目录的app.json指定:requiresext-locale localeszh_CN注意: locales不要写成locale了,我因为写错了导致找了很久_可是在构建时locales只能构建一个语言.如果能构建多个语言,并通过一个”index.html”进行选择加载就能实现B的国际化了.思路如下图:下面是实现方法修改Sencha Cmd项目根目录下app.json的以下属性:enbuildscrispthemeext-theme-crispbootstrapbase$app.dirmanifest$build.id.jsonmicroloaderbootstrap.jscssboot

12、strap.cssoutput$workspace.build.dir/$build.environment/$app.name/$build.idpage./index.html./$build.id.jsondeltasenable falsecachejsoptimizecallParentcssPrefixdefines修改build.xml文件如下:?xml version=1.0 encoding=utf-8project name=$app.name default=.help import file=$basedir/.sencha/app/build-impl.xml/ Th

13、e following targets can be provided to inject logic before and/or after key steps of the build process: The init-local target is used to initialize properties that may be personalized for the local machine.target name=-before-init-local-after-init-localclean target is used to clean build output from

14、 the build.dir.-before-clean-after-clean The general init target is used to initialize all other properties, including those provided by Sencha Cmd.-before-init-after-init target performs the call to Sencha Cmd to build the all-classes.js file.-before-page-after-pagebuild target performs the call to

15、 Sencha Cmd to build the application.-before-build-after-buildmacrodef name=x-run-buildattribute name=targetlocalebuildNamethemebuildIdtheme-localesequentialifequals arg1=locale arg2=thenant dir=$basedir inheritall=false inheritrefs=true target=targetproperty name=compiler.ref.id value=$compiler.ref

16、.id-themeapp.themeext-theme-themeapp.build.dir.suffixcmd.dir$cmd.dirbuild.environment$build.environmentpression.yui$pression.yuibuild.idbuildIdbuild.namebuildName/ant/thenelse$compiler.ref.id-theme-localeapp.localeext-theme-theme-locale/else/if/sequential/macrodefbuild-all depends=build-crisp,build-crisp-touch-init,build-all- Build -build-crispechoBuild $app.name - Crisp Themex-run-build theme=app-build-impl.build/targettarget

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1