六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 18|回复: 0

Light-commons加入I18nBundle

[复制链接]

升级  4.67%

62

主题

62

主题

62

主题

举人

Rank: 3Rank: 3

积分
214
 楼主| 发表于 2013-2-3 14:19:54 | 显示全部楼层 |阅读模式
java里的国际化一般是用ResourceBundle来实现,ResourceBundle.getBundle用的是Properties,Properties只支持iso-8859-1编码,中文要用 \udddd的格式,十分不爽。
因此Light-common 加入ExProperties,方便中文配置。解决了Properties不支持中文的问题,然而ResourceBundle仍然不能用。

现在加入了I18nBundle可以实现常用的国际化。
TestCase
Properties cn =I18nBundle.getBundle("message", "conf", "utf-8", Locale.CHINA); Properties tw = I18nBundle.getBundle("message", "conf", "utf-8", Locale.TAIWAN); Properties fr = I18nBundle.getBundle("message", "conf", "utf-8", Locale.FRENCH); assertEquals("中国名字",cn.getProperty("test.name") ); assertEquals("中文名字",tw.getProperty("test.name") ); assertEquals("English Name", fr.getProperty("test.name"));

#message.conf
test.name=English Name

#message_zh.conf
test.name=中文名字

#message_zh_CN.conf
test.name=中国名字
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表