大佬教程收集整理的这篇文章主要介绍了Cordys HTML5 多语言代码 解读,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Cordys 多语言设计思路
<label for="inputName" data-translatable="true"> User Name </label>
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; }
以上是大佬教程为你收集整理的Cordys HTML5 多语言代码 解读全部内容,希望文章能够帮你解决Cordys HTML5 多语言代码 解读所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。