Archive

Archive for the ‘Java’ Category

Managing Java Properties Files

August 7th, 2009 No comments

Java properties files are a terrific, lightweight format for storing localizable application strings. However, they do have some problems:

Properties files don’t declare their own encoding

There’s not much you can do about this. You just need to make sure your translators always deliver their files in an agreed-upon encoding, usually UTF-8. A good text editor will be able to help you detect whether the encoding is indeed UTF-8 or not.

Which brings me to problem #2:

Java only understands ascii-escaped Unicode, which is not human readable

Here’s the problem. Your translator delivers the following:

app.title=外人にエサを与えないでください。

But before Java can make sense of it, you need to convert it to this:

app.title=\u5916\u4eba\u306b\u30a8\u30b5\u3092\u4e0e\u3048\u306a\u3044

\u3067\u304f\u3060\u3055\u3044\u3002

Once it’s converted to ascii-escaped Unicode, however, then no one can read it, it’s very difficult to know if the conversion worked, and you’ll need to convert back to UTF-8 to make any small change.

So, my advice is to keep the properties in UTF-8 until build time. Make the conversion part of your build process (Ant has a native2ascii task), and keep the UTF-8 encoding files under source control. That way, you’re always dealing with human-readable content, and this whole ascii-escaping business is completely transparent to you.

Categories: Java, Localization, Tech Tags: