You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Norris <th...@gmail.com> on 2005/11/16 14:33:45 UTC

Setting the locale

How do I manually set the locale for tapestry? We want language to be a user
definable thing, rather than relying on the browser. We used to do this in
T3 with a getEngine().setLocale(). This method is still being called and the
Engine keeps the right locale, but localization is still done in some places
based on the browser setting. It seems to ignore the Engine property.

I see that the Infrastructure has a locale, but I haven't found any good
documentation, although that may be a problem on my part, about the
Infrastructure.

-Chris

Re: Setting the locale

Posted by Kent Tong <ke...@cpttm.org.mo>.
Chris Norris <thechrisproject.lists <at> gmail.com> writes:

> I don't see how changing the locale in the engine will ever write this
> cookie. Updating the ThreadLocale service will only happen if the
> infrastructure exists. In our case, we are setting this when the home page
> begins rendering, 

Exactly when? The cookie is set only when a response page is 
rendered. Or you may try:

  void someListener(IRequestCycle cycle) {
    getEngine().setLocale(desiredLocale);
    cycle.cleanup();
    throw new PageRedirectException(this);
  }

> and the infrastructure doesn't exist yet.

Yes it does. It is created before the engine starts to handle
the request.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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


Re: Setting the locale

Posted by Chris Norris <th...@gmail.com>.
Sorry for the multiple posts, but maybe I should explain our localization
more. We don't use different templates. According to the docs, the IEngine's
locale "is used when selecting templates and assets." We do have multiple
.properties files, however. These don't seem to rely on the Engine like the
templates do.

The localization page says this about the setting the locale in the engine:
you must obtain the IEngine and invoke setLocale() on it. This will change
the value stored in the engine (which is used when loading new pages), and:
*Update the hivemind.ThreadLocale service, allowing localized messages from
services to be generated in the correct locale
*Cause an HTTP Cookie to be added to the request so that future requests
from the same client will be in the same locale

I don't see how changing the locale in the engine will ever write this
cookie. Updating the ThreadLocale service will only happen if the
infrastructure exists. In our case, we are setting this when the home page
begins rendering, and the infrastructure doesn't exist yet.



On 11/16/05, Chris Norris <th...@gmail.com> wrote:
> Been doing more research. The RequestLocaleManagerImpl class seems to
manage the Locale that pages are instantiated with. It first checks for a
cookie that has the locale cookie with the name
TapestryConstants.LOCALE_COOKIE_NAME. If that doesn't work, it uses the
request's default locale setting, which must come from the browser.
>
> From what I can tell, the engine's locale is just used for page pool stuff
and as a key for storing engine instances. But I'm not sure.
>
> So my questions are these:
> *Will setting the locale cookie be enough to take care of everything? Are
there any hidden gotchas?
> *What's the best place to plug in to manage the locale stuff myself?
>
>
>
> On 11/16/05, Chris Norris < thechrisproject.lists@gmail.com > wrote:
> > How do I manually set the locale for tapestry? We want language to be a
user definable thing, rather than relying on the browser. We used to do this
in T3 with a getEngine().setLocale(). This method is still being called and
the Engine keeps the right locale, but localization is still done in some
places based on the browser setting. It seems to ignore the Engine property.
> >
> > I see that the Infrastructure has a locale, but I haven't found any good
documentation, although that may be a problem on my part, about the
Infrastructure.
> >
> > -Chris
> >
>
>

Re: Setting the locale

Posted by Chris Norris <th...@gmail.com>.
Been doing more research. The RequestLocaleManagerImpl class seems to manage
the Locale that pages are instantiated with. It first checks for a cookie
that has the locale cookie with the name
TapestryConstants.LOCALE_COOKIE_NAME. If that doesn't work, it uses the
request's default locale setting, which must come from the browser.

>From what I can tell, the engine's locale is just used for page pool stuff
and as a key for storing engine instances. But I'm not sure.

So my questions are these:
*Will setting the locale cookie be enough to take care of everything? Are
there any hidden gotchas?
*What's the best place to plug in to manage the locale stuff myself?

On 11/16/05, Chris Norris <th...@gmail.com> wrote:
>
> How do I manually set the locale for tapestry? We want language to be a
> user definable thing, rather than relying on the browser. We used to do this
> in T3 with a getEngine().setLocale(). This method is still being called and
> the Engine keeps the right locale, but localization is still done in some
> places based on the browser setting. It seems to ignore the Engine property.
>
> I see that the Infrastructure has a locale, but I haven't found any good
> documentation, although that may be a problem on my part, about the
> Infrastructure.
>
> -Chris
>