File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes User to Choose Language Explicitly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "User to Choose Language Explicitly" Watch "User to Choose Language Explicitly" New topic

User to Choose Language Explicitly

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
I know the locale specific resource bundle to be used by <bean:message key="title.something" /> is selected by ActionServlet automatically base on the 'Accept-language' header of the http request (pls correct me if not). But, what if I want to let the user to select the language explicitly in my web page? Say, I want the welcome page to allow user to click language1, language2, etc. Is there any way to force Struts to retrieve the proper resource bundle using application supplied information rather than from the http header?

Thx for any advice.
poornima balagopal
Ranch Hand

Joined: Dec 02, 2003
Posts: 83
I am doing somewhat similar to this in my application. Hope this will help you.
I have a jsp where i am giving the option to select the language and country for the user. When i submit the page, i will get the values in my action class and using those values i am setting the locale in session as follows
session.setAttribute(Globals.LOCALE_KEY,new Locale("es","ES"));
Here i have selected spanish as my language and country. Using that i am creating a locale as es_ES . Corrsponding to that i should have the property file to be loaded as
So when this locale reference comes it will check whether corresponding file is available or not and will load.
Refer ResourceBundle class of java.and also MessageResources class of Struts . These classes will help you and also refer internationalization part in struts.
I agree. Here's the link:
subject: User to Choose Language Explicitly
It's not a secret anymore!