tags:

views:

388

answers:

3

Are there any other better mechanism than resource bundle properties file to localize the application?

A: 

Let me ask you something? what better features are you looking at?

In one application, instead of using resource bundles, we have XML and a small library to handle it.

Abdel Olakara
Sorry, I should have been clear. I don't have any issues in using resource bundle at the same time I shouldn't miss some best practices if other than resource bundle.
Venkat
+2  A: 

Actually, a ResourceBundle does not necessarily read its data from a properties file. ResourceBundle has some kind of logic for resolving where to find data, and looking for the properties file with the same name as the bundle is one aspect of that logic. Reading from a properties file is actually done by a subclass of ResourceBundle, PropertyResourceBundle.

You can implement your own ResourceBundle, which will read (or compute) the translations the way you want. The ResourceBundle Javadoc gives you examples of such implementations. You could write a ResourceBundle that finds the translations in a database, for example.

barjak
A: 

Here's a quote direct from the ResourceBundle javadoc.

The Java Platform provides two subclasses of ResourceBundle, ListResourceBundle and PropertyResourceBundle, that provide a fairly simple way to create resources. As you saw briefly in a previous example, ListResourceBundle manages its resource as a list of key/value pairs. PropertyResourceBundle uses a properties file to manage its resources.

If ListResourceBundle or PropertyResourceBundle do not suit your needs, you can write your own ResourceBundle subclass. Your subclasses must override two methods: handleGetObject and getKeys().

In my opinion, best practice is to use a ResourceBundle subclass of some kind, preferably one that doesn't require you to hack the code to do localization. Reason: it exists, it works, people understand it, don't reinvent the wheel, etc.

Stephen C