JS實現html國際化二

步驟一javascript

<script type="text/javascript" src="../js/jsmart.js"></script>
<script type="text/javascript" src="../js/jquery.i18n.properties-min-1.0.9.js"></script>

步驟二java

//翻譯
 jSmart.prototype.registerPlugin("modifier","translate",function(name,lang){
 	
	 	var name_t,lang_t=lang;
		 $.i18n.properties({
			name:'messageResources',
			language:lang_t!=null?lang_t:'zh_CN',
			path:'../resource/',
			mode:'map',
			callback:function(){
				name_t=$.i18n.prop(name);
			}
		}); 
		return name_t;
});

步驟三jquery

<div  id="test">

<script id="jsmart_tpl" type="text/x-jsmart-tmpl">
<div>
{language|translate:zh_CN}
</div>
</script>
</div>

<script type="text/javascript">
var data={aa:'123',bb:'1234'};
var tpl = new jSmart(document.getElementById('jsmart_tpl').innerHTML);
var res = tpl.fetch(data);
$("#test").append(res);
</script>
相關文章
相關標籤/搜索