ResourceBundle with Database Backend

I

Ilja Booij

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.
 
R

Raymond DeCampo

Ilja said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top