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