开发者

usage example of PropertyResourceBundle(Reader reader) in Java6

I have multiple messages.properties files in utf-8 encoded files(messages_en_US.properties, messages_fr.开发者_StackOverflow社区properties,...). Among these properties files, I have some for Asian languages. This means, characters cannot be represented in ISO-8859-1 encoding and must be represented by Unicode Escapes. I do not want to do this. Based on documentation from link below, if I use the constructor which takes a Reader, it does not have that limitation.

http://download.oracle.com/javase/6/docs/api/java/util/PropertyResourceBundle.html

But, if I do use this constructor, I am losing the functionality that determines the correct properties file based on Locale.

Can someone help me with this?


You shouldn't be instantiating PropertyResourceBundle directly. Use ResourceBundle.getBundle() instead.

Also take a look at the second example under ResourceBundle.Control for how to load alternate formats while still using the resolution hierarchy. The example is for loading XML properties, but should be adaptable to use a UTF-8 encoded InputStream.


It seems they really want you to still use native2ascii. :-(

This way, you can encode your Asian characters as \uxxxx sequences. The ResourceBundle mechanism can load them in this format.

What we do is that we edit the property files in UTF-8, and the build script runs native2ascii on them.

Seeing that Java6 finally supports different encodings for Properties when you load them manually, it would be nice if that support trickled down (up?) to the other pieces that build on properties, such as resource bundles.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜