ITeye博客

Light-commons加入I18nBundle

jasongreen · 2008-07-24 01:32 · light-commons · 企业架构 · Java · Blog · Markdown

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=中国名字

评论(2)

  1. #2 楼 · jasongreen · 2008-07-24 12:50

    多谢支持!

  2. #1 楼 · spiritfrog · 2008-07-24 08:53

    看了一下,还是挺有帮助的,能解决实际问题,关注你的开源项目。

评论功能维护中,当前仅展示历史评论。