I had always assumed that a UTF-8 encoded properties file would allow me to use accented characters for words like français. But today I discovered that while I can encode my files in UTF-8, the Struts framework uses the java.util.Properties class which quite inconveniently doesn't understand unicode characters. From the Javadocs:
When saving properties to a stream or loading them from a stream, the ISO 8859-1 character encoding is used.
So you must use a goofy little utility that ships with the JDK called native2ascii which will convert a UTF-8 encoded properties file into an ASCII file which contains unicode escape codes to represent those characters. You then use this generated file in your Struts application. Fortunately Ant comes with an optional task to run this utility.
To me this all seems rather silly especially when you consider Java has built in support for unicode. Begs the question: Why is the Properties class built like this?
No comments:
Post a Comment