tags:

views:

116

answers:

2

Hi Folks,

I wonder, Why not the properties files of JSF shouldn't/cannot (in eclipse for example) accept non-ASCII characters.

As if I have some properties file named "messages.properties", I've to write in unicode escapped characters for non-ASCII characters, example:

title=\u01af\u0020\u0a3f0
header=\u0ff0\u0020\u0ab1

This means that End-users will not be able to edit theses properties files using regular text editors.

Is there any solution ???

+2  A: 

This stems in the fact that java.util.Properties.load(InputStream) uses ISO-8859-1.

The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes ; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

It has been a problem for ages. I've solved it with struts by implementing custom tags that make encoding transformations, but it is generally a pain.

Java 6 introduces the Properties.load(Writer), which works fine with UTF-8, but it seems it isn't widely adopted yet.

I'd suggest using AnyEdit tools to convert to and from the unicode notation.

As for the end-users - if they are to edit properties files (which sounds strange), then you can let them write in whatever characters they like and later convert the files using native2acii (or a wrapper of it)

Bozho
Thanks any way, I have write simple program to convert to unicoded format text, but I was asking because it will represent a very huge problem for end users!Also, JBoss Tools contains a plugin that allow modification of properties file by writting directly native languages (such as Arabic, chines and so force, )
Mohammed
End users aren't supposed to edit properties files, I guess
Bozho
It is a very small web app, so the end-user is a non-technical deployer that gonna do some changes to properties/css files before deploying
Mohammed
+1  A: 

As per the java.util.Properties API you can make use of the native2ascii tool found in /bin folder of the JDK installation directory to convert UTF-8 properties files to ASCII properties files.

You can keep the "original" properties files (give them for example an .utf8 extension) and use a batch/shell file to convert them like this:

cd c:\path\to\properties\files
c:\path\to\jdk\bin\native2ascii.exe -encoding UTF-8 text_cs.properties.utf8 text_cs.properties
c:\path\to\jdk\bin\native2ascii.exe -encoding UTF-8 text_ja.properties.utf8 text_ja.properties
c:\path\to\jdk\bin\native2ascii.exe -encoding UTF-8 text_zh.properties.utf8 text_zh.properties
# You can add more properties files here.

This way you can just edit the .utf8 files and run the batch/shell script once to do the conversion of native characters to \uXXXX. Also see this blog entry.

BalusC
looks good idea
Mohammed