You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hernan Soulages <he...@epidataconsulting.com> on 2004/04/22 22:17:41 UTC

setLocale 2.0

I sent a message asking about a problem with setLocale. Since I haven't
received any anwser, I think one of three thing has happened:
- You didn't receive it.
- It was too stupid a question to bother anwsering (hope not!).
- Nobody has a cleu of what is happening to me.
Wichever is the case, please anwser so I know I'm getting throught.
Regards
Hernan

> Hi. I have been trying to get to work the i18n in an application I'm
> working on and can't make it work. I found something wrong in the
> setLocale. In the login Action I'm using the following code:
> ---
> 	LoginAdminForm f = (LoginAdminForm) form;
>
> 	if (f.getLang().equals("es")) {
> 		Locale local = new Locale("es");
> 		System.out.println("Espanol: " + local.getLanguage() + "_" +
> local.getCountry() );
> 		setLocale(request, local);
> 	}else if (f.getLang().equals("pt")){
> 		Locale local = new Locale("pt");
> 		System.out.println("Portugues: " + local.getLanguage() + "_" +
> local.getCountry());
> 		setLocale(request, local);
> 	}
>  	System.out.println(request.getLocale().getLanguage() + "_" +
> request.getLocale().getCountry());
> ---
>
> When I select Spanish (f.getLang() equals "es"), I get
> Espanol: es_
> en_
> in the server console. So the setLocale(request, local) isn't working. Any
> ideas why?
> I'm using Tomcat 5.0.19 and Struts 1.1
>
> Thanks in advance
> Hernan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: setLocale 2.0

Posted by Hernan Soulages <he...@epidataconsulting.com>.
Problem solved!
It was all a programming error. We added session.invalidate() after the
setLocale. That made the default Locale to be used.
Good to know that setLocale(myRequest, locale) doesn't set the myRequest
locale (as I assumed), but the Globals.LOCALE_KEY object in the session.

Thanks for the help
Hernan
> I recently used <bean:message> with locale in the way you're describing,
> and
> it picked up the locale that's set as Globals.LOCALE_KEY.  If you want,
> you
> can get the code in http://www.rabago.net/struts/formdef/downloads.htm.
> Look
> for the locale.war sample app.
>
> Hubert
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: setLocale 2.0

Posted by Hernan Soulages <he...@epidataconsulting.com>.
Seems your right.
(Locale) request.getSession().getAttribute(Globals.LOCALE_KEY);
does give me the Locale I just set. My problem is that I wan't to
programatically set the language for all the aplication, including the
<bean:message key="keyname"/> in the JSPs. I thought setLocale() did the
trick. How do I set de Locale for the bean:message tags?

Thanks
Hernan

> My understanding of it (which could be incorrect) is that
> setLocale(request,
> locale) only sets the locale that Struts uses internally.  It doesn't set
> the
> locale that the request object uses, or any other processes that looks for
> locale in the request object.
> If you somehow need the locale that you've set in this code, call "locale
> =
> (Locale) request.getSession().getAttribute(Globals.LOCALE_KEY);" in Struts
> 1.1, or "RequestUtils.getUserLocale(request, null);" in 1.2.
>
> Hubert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org