jump to navigation

Pros and cons of List vs. Property resource bundles December 11, 2006

Posted by globalizer in Java, Localization, Translation, Unicode.
trackback

One of the most common questions asked by developers who are new to Java internationalization is “Should I use ListResourceBundles or PropertyResourceBundles for the translated resources in my application?”

Since I have had to answer that question – or at least give my recommendation – quite a few times, I figured it might be a good idea to post my 2 cents in a place where it might be reasonably easy to google it. And if anybody thinks I am way off on anything, please let me know!

Here are the factors that I see as important to the decision (not necessarily in order of importance):

  1. Capabilities
  2. Ease of use for translators
  3. Ease of use for developers
  4. Ease of use for application maintenance/build/etc.
  5. Performance considerations

The first obvious difference between the capabilities of the 2 choices is the one that is always trotted out: properties files can hold only strings, while you can use ListResourceBundles to localize any kind of object. See this article by John O’Connor for more detail on this difference.

However, I have worked with localization of Java applications for at least 8 years now, and I have never seen a real need to store anything but strings in resource bundles, so in my opinion you can safely ignore this factor.

In my experience, properties files win hands down in all the ‘ease of use categories”: they are easier to work with for translators (the structure is as simple as it can get), and since they require no compilation, they are very easy to work with during test phases, etc., where you want to update the test code frequently. It is also very easy to add additional languages simply by plopping in an additional file.

Properties files do require that the characters be ascii-escaped, but since the native2ascii utility provides the conversion, it is not an issue (and you would need to provide an encoding argument to the compiler for ListResourceBundles, if they are not using the default system encoding).

When you use ListResourcebundles, you also have to remember to change the name of the bundle inside each translated file, to contain the language/country identifier instead of just the base name. Thus,
public class NewResource extends
java.util.ListResourceBundle {

would become
public class NewResource_fr_CA extends
java.util.ListResourceBundle {

for the French version to be used in Canada. Not a big deal, you may say, but definitely an added inconvenience to have to add a step to your build scripts to implement this name change inside each file (or have your translators do it – something that is error prone in my experience).

The one factor that might speak against property resource bundles in the “ease of use” category would be if your application runs on both ASCII and EBCDIC platforms. This might require you to convert your properties files from ASCII to EBCDIC (even when using UTF-8, since the arrangement of control codes is different), or to define your JVM to use an ASCII encoding on your EBCDIC platforms.

As for performance, you might think that ListResourceBundles would obviously be better (and that is the conclusion many people jump to), but you would probably be wrong! Take a look at this Sun tech tip, for instance: http://java.sun.com/developer/JDCTechTips/2004/tt1214.html

This is one of the few assessments I have seen with actual data (admittedly not a huge amount, though) to support the conclusions, and they are not the ones you would expect.

So for now, I have seen no reason to change my advice – use PropertyResouceBundles.

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: