You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jordan Redner <jr...@shopping.com> on 2004/10/21 02:56:13 UTC

Suggestion on Tapestry Locale Detection

Is there a way to override Tapestry's Locale detection?

Like in an interface that you can plug into the app.properties.  Hint,
hint??

We tested Browsers like Opera and Safari, and they seem to pass "en"
instead of "en_US".  It would be nice to intercept this functionality
and plug our own implementation with a handle on the HttpRequest,
perhaps even based on detecting the country from an IP range.

Thoughts??



Jordan




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


Re: Suggestion on Tapestry Locale Detection

Posted by Mind Bridge <mi...@yahoo.com>.
This is a good suggestion for future versions, and it will be essentially
made possible in 3.1, since you can just replace the RequestLocaleManager
that obtains the locale. At the moment this is obtained from the request and
stored in a cookie. You will be able to implement either of the two
strategies described in your emails by replacing that with your own
implementation.


I just wanted to note that you can manually do that at the moment by calling
getLocale() and setLocale() on the engine or by overriding the getLocale()
method in your engine.

For example, you could make your own engine class, and override getLocale()
to examine the request parameters and get the locale from the place you
want. You could check if the browser is Opera, for example, and make the
appropriate locale modification (although I think this is not a matter of
the browser, but rather how it has been configured). Please keep in mind
that getLocale() will be invoked a lot of times, so caching here is
absolutely essential.


Another possibility is to override getEngine() in your servlet. Get the
original code, and replace the line 'Locale locale =
getLocaleFromRequest(context);' with what you need. This is probably easier
and bit less disruptive, although it will not cover all cases.


Finally, you could also use setLocale() to change the locale in your pages
(usually after a submit) and this will not require custom tricks in your
Engine implementation. Keep in mind however that pages loaded in the current
request will not change their locale as they are cached (if they are not,
the locale change will cause other objects to be loaded and that will wreck
havok). Therefore, a new request is needed if the change in locale is to
become active.

This can be done simply by designing the application to go on another page
after the locale change. It can also be done server-side, on the same page,
but it is trickier. There is a way to change the locale, clean the cache and
force another request all on the server side so this is invisble to the
client, by calling cleanup() on the RequestCycle to empty the cache and
throwing a PageRedirectException to force it to reload. The code that I
usually give for this is:

    getEngine().setLocale(.......);
    getPage().getRequestCycle().cleanup();
    throw new PageRedirectException(getPage().getPageName());

Please note that the page here needs to support the Page service on reload
and it will be a different object (because the locale is different). It is
possible to generate a URL to support a different service here (not Page),
but it is a bit trickier.


These are few strategies that you can use. Hope this helps...

-mb


----- Original Message ----- 
From: "Andreas Pardeike" <an...@pardeike.net>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Thursday, October 21, 2004 9:08 AM
Subject: Re: Suggestion on Tapestry Locale Detection


> On 21 okt 2004, at 02.56, Jordan Redner wrote:
>
> > We tested Browsers like Opera and Safari, and they seem to pass "en"
> > instead of "en_US".  It would be nice to intercept this functionality
> > and plug our own implementation with a handle on the HttpRequest,
> > perhaps even based on detecting the country from an IP range.
>
> Second that. It would also allow for using Cookies for that
> functionality.
> That would make it easy to have a "Select your site language" choice at
> i.e.
> the header of a site which then would be persistent if you use
> non-expiring
> cookies.
>
> Just a thought that I had for a while and that was triggered by the
> comment
> above...
>
> Andreas Pardeike
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Suggestion on Tapestry Locale Detection

Posted by Andreas Pardeike <an...@pardeike.net>.
On 21 okt 2004, at 02.56, Jordan Redner wrote:

> We tested Browsers like Opera and Safari, and they seem to pass "en"
> instead of "en_US".  It would be nice to intercept this functionality
> and plug our own implementation with a handle on the HttpRequest,
> perhaps even based on detecting the country from an IP range.

Second that. It would also allow for using Cookies for that 
functionality.
That would make it easy to have a "Select your site language" choice at 
i.e.
the header of a site which then would be persistent if you use 
non-expiring
cookies.

Just a thought that I had for a while and that was triggered by the 
comment
above...

Andreas Pardeike


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