You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Frers Michael <fr...@Sisis.de> on 2003/10/30 16:33:18 UTC
Locale - how to set?
Hello
just a simple question
how can set the actual used local?
i have two propertie files:
application.properties
application_de.properties
application_en.properties
struts takes as default application_de.properties
how can i make it that a user can click a GreatBritain flag and then the application is displayed in english?
Thanks for any help
Michael
Re: Locale - how to set?
Posted by Kris Schneider <kr...@dotech.com>.
Okay, this seemed like a useful utility action to have hanging around, so here's
an example. Note that I've included a couple of lines the also update JSTL's
FMT_LOCALE config variable. Also note that the action expects a form that
exposes the following properties: language, country, and variant (it doesn't
matter if the form's a vanilla ActionForm or a flavor of DynaActionForm).
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.jstl.core.Config;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LocaleAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
String language = StringUtils.clean(BeanUtils.getProperty(form,
"language"));
String country = StringUtils.clean(BeanUtils.getProperty(form, "country"));
String variant = StringUtils.clean(BeanUtils.getProperty(form, "variant"));
if (language.length() > 0) {
Locale locale = new Locale(language, country, variant);
setLocale(request, locale);
HttpSession session = request.getSession(true);
Config.set(session, Config.FMT_LOCALE, locale);
}
return mapping.findForward("success");
}
}
Quoting Kris Schneider <kr...@dotech.com>:
> See Action.setLocale
>
> Quoting Philip Mark Donaghy <go...@yahoo.com>:
>
> >
> > --- Frers Michael <fr...@Sisis.de> wrote:
> > > Hello
> > >
> > > just a simple question
> > >
> > > how can set the actual used local?
> > >
> > > i have two propertie files:
> > >
> > > application.properties
> > > application_de.properties
> > > application_en.properties
> > >
> > > struts takes as default application_de.properties
> > >
> > > how can i make it that a user can click a
> > > GreatBritain flag and then the application is
> > > displayed in english?
> >
> > You should take a look at the struts-validator webapp.
> > Here is the basic code...
> >
> > locale = new java.util.Locale(language, country);
> >
> > or
> >
> > locale = new java.util.Locale(language, "");
> >
> > and
> >
> > session.setAttribute(Globals.LOCALE_KEY, locale);
> >
> > where language is en and country is UK
> >
> > That should do it.
> >
> > Phil
> >
> > >
> > > Thanks for any help
> > >
> > > Michael
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Locale - how to set?
Posted by Kris Schneider <kr...@dotech.com>.
See Action.setLocale
Quoting Philip Mark Donaghy <go...@yahoo.com>:
>
> --- Frers Michael <fr...@Sisis.de> wrote:
> > Hello
> >
> > just a simple question
> >
> > how can set the actual used local?
> >
> > i have two propertie files:
> >
> > application.properties
> > application_de.properties
> > application_en.properties
> >
> > struts takes as default application_de.properties
> >
> > how can i make it that a user can click a
> > GreatBritain flag and then the application is
> > displayed in english?
>
> You should take a look at the struts-validator webapp.
> Here is the basic code...
>
> locale = new java.util.Locale(language, country);
>
> or
>
> locale = new java.util.Locale(language, "");
>
> and
>
> session.setAttribute(Globals.LOCALE_KEY, locale);
>
> where language is en and country is UK
>
> That should do it.
>
> Phil
>
> >
> > Thanks for any help
> >
> > Michael
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Locale - how to set?
Posted by Philip Mark Donaghy <go...@yahoo.com>.
--- Frers Michael <fr...@Sisis.de> wrote:
> Hello
>
> just a simple question
>
> how can set the actual used local?
>
> i have two propertie files:
>
> application.properties
> application_de.properties
> application_en.properties
>
> struts takes as default application_de.properties
>
> how can i make it that a user can click a
> GreatBritain flag and then the application is
> displayed in english?
You should take a look at the struts-validator webapp.
Here is the basic code...
locale = new java.util.Locale(language, country);
or
locale = new java.util.Locale(language, "");
and
session.setAttribute(Globals.LOCALE_KEY, locale);
where language is en and country is UK
That should do it.
Phil
>
> Thanks for any help
>
> Michael
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org