Hi Chris,
We tried various ways of solving this problem, and in the end wrote our
own implementation of RequestLocaleManager - the only relevant bit of
the code is this:
public Locale extractLocaleForCurrentRequest()
{
Locale locale = getUserLocale();
if (locale == null)
locale = mRequest.getLocale();
mThreadLocale.setLocale(locale);
return locale;
}
You can then use the persistLocale method to store it in the
session/cookie or wherever if you want.
You can get the locale from wherever you like (session, cookie,
database, ldap...) and then set it on the threadLocale instance. This is
enough to get pages to load the correct property files. Inject the
threadLocale instance, and the WebRequest if you want to parse cookies.
Then supply your implementation and it will replace the standard one:
<implementation
service-id="tapestry.request.RequestLocaleManager">
<invoke-factory>
<construct class="UserRequestLocaleManager">
<set-service
property="principalManagerHolder" service-id="PrincipalManagerHolder"/>
<set-service property="request"
service-id="tapestry.globals.WebRequest"/>
<set-service property="threadLocale"
service-id="hivemind.ThreadLocale"/>
</construct>
</invoke-factory>
</implementation>
Best wishes
John
-----Original Message-----
From: Chris Norris [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 16, 2005 5:42 PM
To: Tapestry users
Subject: Re: Setting the locale
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 <[EMAIL PROTECTED]> 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 < [EMAIL PROTECTED] > 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
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]