Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Done https://issues.apache.org/jira/browse/WICKET-2533 Cheers Per - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Olivier Bourgeois schrieb: Well, you can't change the behaviour of ServletRequest.getLocale() unless you want to patch your servlet container :) But you make me think it would be great in the Servlet API to have something like setAcceptedLocales(Enumeration e) and let the servlet container do the work of matching the browser locale with your application supported locales. Anyway, it's out of Wicket's scope :-) What you can do is do the work in your overloaded WebSession.getLocale() : @Override public Locale getLocale() { Enumeration _enum = ((WebRequest) request).getHttpServletRequest().getLocales(); // Do your work with locales _enum here return request.getLocale(); }; getLocales() returns what you are looking for, in my case it is : [fr, sv, ar, bg, zh_CN, it, en] Ok didn't checked that in the application itself until now. In my tests it isn't working because MockHttpRequest.getLocales only returns the first locale. So problem maybe related to test. But with my test-first approach i hit the wall on that. It seems that i have to add a jira for it. Cheers Per - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Well, you can't change the behaviour of ServletRequest.getLocale() unless you want to patch your servlet container :) But you make me think it would be great in the Servlet API to have something like setAcceptedLocales(Enumeration e) and let the servlet container do the work of matching the browser locale with your application supported locales. Anyway, it's out of Wicket's scope :-) What you can do is do the work in your overloaded WebSession.getLocale() : @Override public Locale getLocale() { Enumeration _enum = ((WebRequest) request).getHttpServletRequest().getLocales(); // Do your work with locales _enum here return request.getLocale(); }; getLocales() returns what you are looking for, in my case it is : [fr, sv, ar, bg, zh_CN, it, en] 2009/10/19 Per Newgro > Hi Olivier, > > you wrote exactly what i did. But if you check the extraction of locale > from request > to provide it in session, you can see that only first accepted language is > evaluated and used if not-null. > But if you assume that first accpeted language is CHINESE and second is > FRENCH and the > application is supporting FRENCH you don't have any chance to get the > second locale. > > And thats my problem. > > Cheers > > Per > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Hi Olivier, you wrote exactly what i did. But if you check the extraction of locale from request to provide it in session, you can see that only first accepted language is evaluated and used if not-null. But if you assume that first accpeted language is CHINESE and second is FRENCH and the application is supporting FRENCH you don't have any chance to get the second locale. And thats my problem. Cheers Per - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Ho well, I didn't understood correctly your question, sorry. Have you tried tho use a custom WebSession ? - in your WebApplication class overload the newSession method : @Override public Session newSession(Request request, Response response) { return new YourCustomSession(this, request); } - create the class YourCustomSession extending WebSession, then override getLocale() : @Override public Locale getLocale() { // TODO Auto-generated method stub return super.getLocale(); } in YourCustomSession you have access to the Request locale that you can restrict to only supported values in your custom getLocale(). 2009/10/19 Per Newgro > Hi Olivier > >> And the overload of getLocale() would'nt work ? >> >> >> > I don't see how it could solve my problem. What i try is to filter the > locales assignable to session. > It will be assigned in Application.newSession(Request, Response) by usage > of the Accepted-Langauge > value in header of response. That seems the right place to ensure only > supported languages. > > WIth overwriting Page.getLocale() i don't see the way on howto get the > accepted locales of client browser. > > Thanks > > Per > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Hi Olivier And the overload of getLocale() would'nt work ? I don't see how it could solve my problem. What i try is to filter the locales assignable to session. It will be assigned in Application.newSession(Request, Response) by usage of the Accepted-Langauge value in header of response. That seems the right place to ensure only supported languages. WIth overwriting Page.getLocale() i don't see the way on howto get the accepted locales of client browser. Thanks Per - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
2009/10/16 Per Newgro > Hi Olivier, > > isn't mod_jk a bit heavyweight for this little usecase? > I don't know your case, for mine, every project I worked on already had a mod_jk. And it is a common pattern with J2EE development : simply because when you have static resources to serve on a high traffic site, then it is Tomcat who becomes heavyweight :) > > I like the locale usage of wicket. It is like magic and i don't have to > worry about it. > All i want to add to my application is the check for a supported locale on > session startup. > > But thanks anyway. > > Per > And the overload of getLocale() would'nt work ?
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
Hi Olivier, isn't mod_jk a bit heavyweight for this little usecase? I like the locale usage of wicket. It is like magic and i don't have to worry about it. All i want to add to my application is the check for a supported locale on session startup. But thanks anyway. Per - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Howto accept other then first locale in HTTP header "Accept-Language"?
If you are using Apache + Mod-JK in front of your webapp, you can use mod_rewrite features to rewrite the HTTP headers and force the accepted language field to a value your application supports. Otherwise you can simply create a class that extends WebPage, then override the getLocale() method and make all your page extend this class : @Override public Locale getLocale() { // TODO Implement a locale mapping and fallback return super.getLocale(); } 2009/10/16 Per Newgro > > A solution would be to extract the accepted langauges myself from header > and set default > only if no supported locale is accepted by client-browser. But then i have > to (re)-implement > language extraction similiar to MockHttpServletRequest.getLocale(). But > this breaks the famous > "Don't repeat yourself" programmming rule :-). > > A much better approch would be to provide a list of supported locales in > application settings. > So the request could set in automatically and use Locale.getDefault() only > on last exit. > > What do you think? > Per > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Howto accept other then first locale in HTTP header "Accept-Language"?
Hi, after solving my problem with testing session locale filtering in thread "Wickettester change locale of request" i found a new problem. Assume your client browser accepts CHINA - locale by default (first) and ENGLISH as second. Your application supports FRENCH and ENGLISH locale. The system locale is FRENCH. All works great for the localization of wicket components by usage of java properties fallback system. But what happens if you try to use the locale in session for your data-localization (db-access etc)? Session gets the locale from request which is getting it out of HTTP header "Accept-Language". Because first locale is defined - CHINA is set to session. If i filter session locale as described in other thread i can see that CHINA is not supported. But i don't have a chance to get the other accepted locale (ENGLISH). There is a similiar discussion here http://issues.apache.org/struts/browse/STR-2351 . A solution would be to extract the accepted langauges myself from header and set default only if no supported locale is accepted by client-browser. But then i have to (re)-implement language extraction similiar to MockHttpServletRequest.getLocale(). But this breaks the famous "Don't repeat yourself" programmming rule :-). A much better approch would be to provide a list of supported locales in application settings. So the request could set in automatically and use Locale.getDefault() only on last exit. What do you think? Per - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org