Two Laptop Bag*
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "User to Choose Language Explicitly" Watch "User to Choose Language Explicitly" New topic
Author

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
Hi
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 fileName_es_ES.properties.
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: http://aspose.com/file-tools
 
subject: User to Choose Language Explicitly