1 基本介绍
个人建议使用jquery.i18n.properties-1.0.x版本,高版本可能会出现意想不到的问题。
我在git上传了jquery.i18n.properties-1.0.x、jquery.i18n.properties-1.2.7(最新版本)和jquery-1.9.0.js源文件,有需要的可以下载: https://github.com/MasonYyp/jquery.i18n.git
在jquery.i18n.properties设置properties对应的结构如下图:
1.1 在jquery.i18n.properties-1.0.x中
(1) 如果没报错,并且出现key的原始信息(如下图),则是properties的路径出问题了,检查name、language和path,注意path中路径最后最好加上”/”,在新的版本中可能不需要。
1.2 在jquery.i18n.properties-1.2.7中
(1) 如果出现“Cannot read property 'length' of undefined”的错误,则是properties的路径出现了问题,检查name、language和path是否正确。
(2) 如果出现“settings is not defined”的错误,请将jquery.i18n.properties1.7.2.min.js更换为jquery.i18n.properties1.7.2.js,如果还有问题,请更换为其他版本的jquery.i18n.properties。
2 源程序和运结果
本文使用两种方法,设置国际化
2.1 在回调函数中调用

// 源代码
function set_properties_callback(local) {
$.i18n.properties({
name: 'messages', // 资源文件名称
path: './js/language/', // 资源文件所在目录路径
mode: 'map', // Map的方式使用资源文件中的Key
language: local, // 设置的语言
cache: false,
encoding: 'UTF-8',
callback: function () { // 回调方法
alert("回调函数中:"+$.i18n.prop('msg_hello'));
}
});
}
2.2 不在回调函数中调用

// 源代码
function set_properties(local) {
$.i18n.properties({
name: 'messages', // 资源文件名称
path: './js/language/', // 资源文件所在目录路径
mode: 'map', // Map的方式使用资源文件中的Key
language: local, // 设置的语言
cache: false,
encoding: 'UTF-8'
});
alert("不在回调函数中:"+$.i18n.prop('msg_hello'));
}