Create a from in your jsp (I do this in my welcome page), something like
(don't cut and paste this as I just quickly typed the following)

<html:form action = "setLocale.do" >
Choose Language :<html:select name="locale">
<html:option value="English">English</html:option>
<html:option value="Spanish">Spanish</html:option>
</html:select><html:submit value="SUBMIT">
</html:form></right>

In the Action class, say SetLocaleAction, determine the selected value from
your jsp and do a setLocale like the code below. From what I've been doing
so far, once I've set the locale, it is persisted throughout the entire
session so all my prompts and messages will be displayed in the
user-selected language.


public ActionForward perform(ActionMapping mapping, ActionForm form,
     HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
     ActionErrors errors = new ActionErrors();

     try {

          String locale = request.getParameter("locale");
          if (locale.equals("Spanish")) {
               Locale newlocale = new Locale("es","");
               setLocale(request, newlocale);
          }
          else {
               Locale newlocale = new Locale("en","");
               setLocale(request, newlocale);
          }

          return new ActionForward(mapping.getInput());

     } catch (Throwable e) {
          e.printStackTrace();
          ActionError error = new ActionError(e.getMessage());
          errors.add(ActionErrors.GLOBAL_ERROR, error);
     }

     saveErrors(request, errors);
     return new ActionForward(mapping.getInput());


}


You should have created ApplicationResources.properties_es beforehand.





Lisa van Gelder <[EMAIL PROTECTED]> on 05/14/2002 03:57:08 AM

Please respond to "Struts Users Mailing List"
      <[EMAIL PROTECTED]>

To:   'Struts Users Mailing List' <[EMAIL PROTECTED]>
cc:
Subject:  RE: changing locale from jsp


Actually, maybe the question should be how do I set the "LOCALE_KEY" for my
session?

I can then change the locale stored under "LOCALE_KEY" myself.

Lisa

--
To unsubscribe, e-mail:   <
mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <
mailto:[EMAIL PROTECTED]>






**********************************************************************
Please Note:
The information in this E-mail message, and any files transmitted
with it, is confidential and may be legally privileged.  It is
intended only for the use of the individual(s) named above.  If you
are the intended recipient, be aware that your use of any confidential
or personal information may be restricted by state and federal
privacy laws.  If you, the reader of this message, are not the
intended recipient, you are hereby notified that you should not
further disseminate, distribute, or forward this E-mail message.
If you have received this E-mail in error, please notify the sender
and delete the material from any computer.  Thank you.
**********************************************************************



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to