Cordys HTML5 多语言代码 解读
2015-10-29 15:19
756 查看
Cordys 多语言设计思路
如果页面上需要翻译 则添加自定义标签。 data-translatable='true' 则可以利用JQuery 找到所有的对象$("data-translatable='true'")
<label for="inputName" data-translatable="true"> User Name </label>
如果页面上需要翻译 则添加自定义标签。 data-translatable='true' 则可以利用JQuery 找到所有的对象$("data-translatable='true'")
var selector = "[data-translatable='true']"; $(selector).each(function () { var $this = $(this); var label_name=$this.text().trim();//得到label name,然后利用label name去匹配,把对应的值找出来。 $this.text(getMessage($this.text().trim())); }
//利用Ajax读取本地文件 $.ajax({ type: "GET", url: "translation/html5sdk/sdkmessagebundle_zh-CN.xml", async: true, cache: true, success : function(response){ res=response; } });
//将本地文件转为Json数组 $.cordys.json.xml2js(res) //找到某个对象 dictionary=$.cordys.json.find($.cordys.json.xml2js(res), "dictionary"); // var self = this; this.path = path; this.dictionary = dictionary; this.getMessage = function () { var id = arguments[0], label = null, ttext = ""; if (self.dictionary) { label = $.cordys.json.find(self.dictionary, "@textidentifier", id); } ttext = label ? (label[language] ? (label[language].text || label[language]) : id) : id; if (arguments.length > 1) { var args = Array.prototype.slice.call(arguments).slice(1); ttext = ttext.replace(/\{(\d+)\}/g, function () { return typeof(args[arguments[1]]) !== "undefined" ? args[arguments[1]] : arguments[0]; }); } return ttext; }
相关文章推荐
- HTML5规范~
- html5+css3
- Html5 本地存储
- HTML5鼠标hover的时候图片放大的效果展示
- cordys HTML5 SSO 开发注意点
- 图片翻转
- HTML5 ajax上传附件
- 移动前端头部标签(HTML5 head meta)
- HTML5文件上传FileReader API
- win10 Build 10565中Edge浏览器新增对HTML5视频的播放控制及下载
- 基于百度地图的HTML5地理位置定位实例
- HTML5画矩形
- HTML5 中的可缩放矢量图形(SVG)
- 常见的2种HTML5错误语法
- HTML5 drag & drop 拖拽与拖放简介
- HTML5 placeholder在低版本浏览器的解决方法
- 使用HTML5中postMessage知识点解决Ajax中POST跨域问题
- 基于HTML5 Canvas的刮奖(刮刮卡)小控件(Scratch card based on HTML5 Canvas)
- html5 canvas标签
- 盒子模型