Localization

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Localization

Daniel Woo
Hi guys,

I am a new baby on Stripes and after I made some tests I feel it's really a
lightweight and grace web framework, I am evaluating using it in my next
project.
But I got a question for the localization, from the document I know that the
framework is using request.getLocale() to determine the locale users want, then
it uses resource bundle StripesResources.properties to retrive messages. My
problem is that the locale you get from request.getLocale() is actually defined
in web browsers, eg, IE->Tools->Internet Options->Languages, but I can't
persuade my customers to change the IE settings each time they want to switch
locales. What my customers want is just a combox at the top of each page, so
you can switch the locale anytime without changing browser settings.

In Struts, you can just do it just by

session.setAttribute(Globals.LOCALE_KEY, locale);

then the action will check the user's prefered locales in this order:
1. check explicitly passed locale
1. check session only if session exists
2. check request.getLocale()
so the appropriate resouce bundle is used according to the locale.

Could you consider about this pattern? Or do you have any alternative ways so I
can get localized validation messages etc?

Thanks & Regards,
Daniel


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Localization

Tim Fennell-3
Hi Daniel,

Well, most of Stripes uses request.getLocale() to retrieve the  
locale, but that's only because very early in the request cycle  
Stripes wraps the HttpServletRequest object and sets on it the Locale  
that should be used to service the request.

So I think the question is really, how does the locale get set up  
front?  The DefaultLocalePicker looks at the value(s) returned by  
request.getLocales() and the list of supported locales for the  
application (from a config parameter) and then attempts to find the  
best match.

So it sounds like what you really want is an extended LocalePicker that:
   1. Uses a request parameter if it is present
   2. Uses a session attribute if #1 doesn't pan out and the user has  
a session
   3. Falls back to the Stripes default behaviour?

You should be able to do this pretty easily with a custom subclass of  
DefaultLocalePicker.  Something like:

public MyLocalePicker extends DefaultLocalePicker {
     public Locale pickLocale(HttpServletRequest request) {
         if (request.getParameter("locale") != null) {
             Locale l = new Locale(request.getParameter("locale"));
             request.getSession().setAttribute("locale", l);
             return l;
         }
         else if (request.getSession(false) != null &&
                  request.getSession().getAttribute("locale") != null) {
             return (Locale) request.getSession().getAttribute
("locale");
         }
         else {
             return super.pickLocale(request);
         }
     }
}

This could then be configured as using an init param:

<init-param>
     <param-name>LocalePicker.Class</param-name>
     <param-value>com.myco.MyLocalePicker</param-value>
</init-param>

Does that work for you?

-t


On Oct 15, 2006, at 12:04 AM, Daniel Woo wrote:

> Hi guys,
>
> I am a new baby on Stripes and after I made some tests I feel it's  
> really a
> lightweight and grace web framework, I am evaluating using it in my  
> next
> project.
> But I got a question for the localization, from the document I know  
> that the
> framework is using request.getLocale() to determine the locale  
> users want, then
> it uses resource bundle StripesResources.properties to retrive  
> messages. My
> problem is that the locale you get from request.getLocale() is  
> actually defined
> in web browsers, eg, IE->Tools->Internet Options->Languages, but I  
> can't
> persuade my customers to change the IE settings each time they want  
> to switch
> locales. What my customers want is just a combox at the top of each  
> page, so
> you can switch the locale anytime without changing browser settings.
>
> In Struts, you can just do it just by
>
> session.setAttribute(Globals.LOCALE_KEY, locale);
>
> then the action will check the user's prefered locales in this order:
> 1. check explicitly passed locale
> 1. check session only if session exists
> 2. check request.getLocale()
> so the appropriate resouce bundle is used according to the locale.
>
> Could you consider about this pattern? Or do you have any  
> alternative ways so I
> can get localized validation messages etc?
>
> Thanks & Regards,
> Daniel
>
>
> ----------------------------------------------------------------------
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Stripes-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/stripes-users


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users