---
title: "Light-commons加入I18nBundle"
author: "jasongreen"
date: "2008-07-24T01:32:05Z"
tags: ["Blog", "Java"]
categories: ["企业架构"]
slug: "light-commons-i18nbundle"
draft: false
lastmod: "2008-07-24T01:32:05Z"
id: 218804
url: "https://jasongreen.iteye.com/blog/218804"
---

java里的国际化一般是用ResourceBundle来实现，ResourceBundle.getBundle用的是Properties，Properties只支持iso-8859-1编码，中文要用 \udddd的格式，十分不爽。
因此[Light-common 加入ExProperties，方便中文配置](http://jasongreen.iteye.com/blog/205889)。解决了Properties不支持中文的问题，然而ResourceBundle仍然不能用。

现在加入了I18nBundle可以实现常用的国际化。
TestCase

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