jquery.i18n.properties使用小记

[url]http://blog.sina.com.cn/s/blog_5919afb30100fw84.html[/url]

项目主页: [url]https://code.google.com/p/jquery-i18n-properties/[/url]

一直在寻找js的i18n解决方案,今天使用了一下jquery.i18n.properties觉得很不错,向大家推荐一下。

在jquery.1.3.2下调试过程

1、在js/i18n/目录下创建message.properties,message_zh_CN.properties,message_en_US.properties三个文件,推荐使用eclipse下的插件resourcebundleeditor编辑文档,文档存为ISO-8859-1或utf-8.
英文文件中插入
[color=darkblue] msg_hello = Hello
msg_world = World
msg_complex = Good morning {0}! [/color]
中文同上就不写了。
2、在使用前初始化jquery.i18n.properties。

// This will initialize the plugin
// and show two dialog boxes: one with the text "Olá World"
// and other with the text "Good morning John!"
jQuery.i18n.properties({
name:'message', //使用资源文件名称
path:'js/i18n/', //资源文件所在路径
mode:'both', //调用方式,可用值‘vars’ (default) 变量方式, ‘map’map方式 or ‘both’两者均支持
language:'en_US', //语言
callback: function() {
//回调函数
// We specified mode: 'both' so translated values will be
// available as JS vars/functions and as a map

// Accessing a simple value through the map 通过map调用
jQuery.i18n.prop('msg_hello');
// Accessing a value with placeholders through the map 带参数Map调用,john会替换相应参数,支持多个参数
jQuery.i18n.prop('msg_complex', ['John']);

// Accessing a simple value through a JS variable通过变量调用
alert(msg_hello +' '+ msg_world);
// Accessing a value with placeholders through a JS function通过变量函数方式替换占位符,支持多个参数,不过在360浏览器下测试失败,在chrome下成功
alert(msg_complex('John'));
}
});

使用心得:
建议使用工具编辑i18n文件,方便。
为了获得最好的兼容性,还是使用map方式访问吧
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值