js读取properties配置文件

    js读取properties配置文件,大多数的方法都是引入一个jQuery的插件jquery.i18n.properties,不能否认,确实可行,下面就让咱们来看下具体的使用。javascript

    涉及到的js可从该网址的示例代码中下载得到:java

    https://www.ibm.com/developerworks/cn/web/1305_hezj_jqueryi18n/jquery

    jQuery.i18n.properties() 用法:web

jQuery.i18n.properties({ 
   name:'strings',// 资源文件名称
   path:'bundle/',// 资源文件所在目录路径
   mode:'both',// 模式:变量或 Map 
   language:'pt_PT',// 对应的语言
   cache:false, 
   encoding: 'UTF-8', 
   callback: function() {// 回调方法
   } 
});

    在上面的配置中,又尤为要注意的是资源文件路径,若是路径出错,读取文件确定会失败,从 jquery.i18n.properties-1.0.9.js中也能够看出。除了几个必要的配置,如:name、path、mode加上callback回调方法,其余的能够去掉,在callback回调方法中如无特别须要,可没必要添加具体实现。.net

    jQuery.i18n.prop(key) 使用:插件

$.i18n.prop('myKey')

    在运行 jQuery.i18n.properties()后,可经过$.i18n.prop(key)的方式获取配置文件中已配置的信息,如code

function loadProperties(){
	jQuery.i18n.properties({
		name:'strings',
		path:'static/js/jiajieJs/',
		mode:'map',
		callback: function() {
			
		}
	});
}
function duquInfo(){
   loadProperties();
   $.i18n.prop('myKey');
}

    配置文件若无其余语言方面的须要,能够只写一个,如strings.properties,内容如ip

myKey=123jdksk456

    亲测可用。资源

相关文章
相关标签/搜索