aspose file tools*
The moose likes Servlets and the fly likes Resource Bundles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Resource Bundles" Watch "Resource Bundles" New topic
Author

Resource Bundles

David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 196

The more I read up on this the more confused I become. My web application consists of a single servlet and a few .jsp files. When a user logs on his credentials are checked against a database which contains a reference to his prefered language. There is no guarantee that all users will have the same language. Lets says for example my user base is Dutch but when I logon I want to get English menus. I can retrieve and store the prefered language as a string in a session variable.

I don't see how a single resource bundle can help me as it wants to know the locale, which could very well be differnet for each session.

Should I be creating a resource bundle for each possible language I support and then put some conditional logic in a routine which looks for the users preferred language and then calls the appropriate resource bundle to get the translation ?

If I do it that way then I will end up with some code I need to change whenever I add a new language?

Sorry if it's a silly question

Thanks in advance

Dave
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're talking about property files, right? There should be one for each language, with the country code appended at the end.
David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 196

I understand that much, but when you access those via a resource bundle you specify the language that you want it to work with. However each call may be for a different user and different language. Does this mean I have to create a new instance of resourcebundle for each user ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not necessarily per-user, but per locale, sure. The details of that may be handled by the JDK, though--I've only *very* rarely had to deal with resource bundles directly--I almost always only care about localized text, which is almost always handled by whatever framework I happen to be using.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Yes, you need a bundle per locale if you are handling them yourself. Or you could store a per-user bundle in the session.

If the JSPs pages are the only place that deal with localized text, just use the JSTL's fmt tags and let them do the hard work for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resource Bundles