ResourceBundle with Database Backend  
Author Message
Ilja Booij





PostPosted: 2005-9-21 22:35:00 Top

java-programmer, ResourceBundle with Database Backend Hi all,

We're busy creating a web application that needs different localization.
ResourceBundles would probably be the best thing to use for this. However,
we would like to use a database as the backend for the ResourceBundle.
This would make changing and adding translated strings much easier. We
would like our client to be able to do this himself, using a front end we
will write.

From what I understand of ResourceBundles, we would have to create a
ResourceBundle class for each translation. We'd like to create just one
subclass of ResourceBundle however, which handles all translations. Is
this possible? I can't find any examples of how this should work..

thanks for thinking along, please tell me if my question isn't completely
clear or something like that,

Ilja Booij
MMS2P B.V.
 
Raymond DeCampo





PostPosted: 2005-9-26 6:20:00 Top

java-programmer >> ResourceBundle with Database Backend Ilja Booij wrote:
> Hi all,
>
> We're busy creating a web application that needs different localization.
> ResourceBundles would probably be the best thing to use for this. However,
> we would like to use a database as the backend for the ResourceBundle.
> This would make changing and adding translated strings much easier. We
> would like our client to be able to do this himself, using a front end we
> will write.
>
> From what I understand of ResourceBundles, we would have to create a
> ResourceBundle class for each translation. We'd like to create just one
> subclass of ResourceBundle however, which handles all translations. Is
> this possible? I can't find any examples of how this should work..
>
> thanks for thinking along, please tell me if my question isn't completely
> clear or something like that,
>

I think you could do something with a custom class loader here. You can
use ResourceBundle.getBundle(String,Locale,ClassLoader) to tell
ResourceBundle to load the bundles using your custom class loader. Now
just implement your class loader to fetch the values from the database
and you are all set. (OK, there are probably a few more details, but
you get the idea.)

Looking at the documentation details of ResourceBundle, it looks like
all you need to implement is ClassLoader.getResource(). I suppose it
depend on whether you want to generate class bytecode or input for
PropertyResourceBundle.

I suppose another way to go is to make a custom extension of
ResourceBundle that reads the data from the database. Then you need a
custom factory method like ResourceBundle.getBundle() to handle loading
the proper one.

HTH,
Ray

--
XML is the programmer's duct tape.