• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

User to Choose Language Explicitly

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic