ResourceBundle usage

R

Ratso

Hello,

I am still expanding my java knowledge, and just came across ResourceBundle
as I was looking for how to best implement translations in my program.
I do, however, have a problem seeing how to use them correctly, how were
they intended?

I am thinking I want to store my translations in the database, and I do not
want to read them all at startup and keep them in memory while the program
is running, so I need some kind of caching functionality. I was planning to
group my translations, for example all labels belonging in this screen is
one group, all frequently-used phrases like "ok" "cancel" across the system
in one group and so on, so that I can read a group at a time.

Now, what I don't get is how to map the bundles to my translations. I see
the bundles say they have built-in caching functionality, indicating they
will not destroy the bundle right away as desired, but for that to have any
effect I would think I need to separate my translations into a number of
bundles. Is it intended to work like I map one bundle to one of my intended
caching-groups, so that any one bundle contains a group and is loaded in its
entirety? In that case I could probably extend ListResourceBundle and fill
up the list with data from the database.

However if that is the case, that would mean I need to create a new class
for each supported Locale every time I add a new group of translations (or a
new screen, which according to my thinking would constitute one group) ?
Sounds awkward to me.

And if this is not the case, say I just have one bundle, I could extend
ResourceBundle itself, and take responsibility for caching in and out values
from the database myself, but if so I am starting to think it just causes me
more work and why would I want to use ResourceBundles at all.

I would appreciate it if somebody would care to give me an idea of actual
usage of ResourceBundles in a growing product; point me in a good
design-direction.


MortenT
 
M

Mark Space

Ratso said:
I would appreciate it if somebody would care to give me an idea of actual
usage of ResourceBundles in a growing product; point me in a good
design-direction.

I didn't really follow everything you said in your post. There were too
many "but in this case I might..." for me to really grasp what you are
trying to execute. A couple of SSCCEs might help clarify where exactly
you see an issue.

In the meantime, see if either of these help:

<http://java.sun.com/docs/books/tutorial/i18n/resbundle/index.html>

<http://www.netbeans.org/kb/60/java/gui-automatic-i18n.html>

That second link is a good reason to stick to established standards like
ResourceBundles. The NetBeans IDE (and I'm sure many other IDEs) will
automatically generate ResourceBundles to localize many types of objects
you produce. This can be a big boost to productivity for you, and I'd
definitely call it a "good design direction."
 

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

Forum statistics

Threads
474,001
Messages
2,570,249
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top