You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bogdan Calmac <bc...@gmail.com> on 2007/03/09 16:47:35 UTC

T5 - Changing Locale

Is it possible in Tapestry 5 to programatically change the locale for
a sesison similar to IEngine.setLocale() from Tapestry 4?

In my case I want to set the locale after the login into the
application (locale is stored in the user profile) and not rely on the
browser locale.

Thank you,

Bogdan Calmac.

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


Re: T5 - Changing Locale

Posted by Hugo Palma <hu...@gmail.com>.
hey, did you copy my reply or did i copy yours ? :o)

Pablo Ruggia wrote:
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html 
>
>
> "Tapestry does not yet support changing the locale, but that will be
> available shortly. The intent is to mimic Tapestry 4 behavior: store a
> cookie on the client to provide the default for the locale on the next
> visit, and store a locale name in the session (if a session exists). 
> TODO: I
> believe this has been implemented by Kent."
>
> On 3/9/07, Bogdan Calmac <bc...@gmail.com> wrote:
>>
>> Is it possible in Tapestry 5 to programatically change the locale for
>> a sesison similar to IEngine.setLocale() from Tapestry 4?
>>
>> In my case I want to set the locale after the login into the
>> application (locale is stored in the user profile) and not rely on the
>> browser locale.
>>
>> Thank you,
>>
>> Bogdan Calmac.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: T5 - Changing Locale

Posted by Pablo Ruggia <pr...@gmail.com>.
http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html

"Tapestry does not yet support changing the locale, but that will be
available shortly. The intent is to mimic Tapestry 4 behavior: store a
cookie on the client to provide the default for the locale on the next
visit, and store a locale name in the session (if a session exists). TODO: I
believe this has been implemented by Kent."

On 3/9/07, Bogdan Calmac <bc...@gmail.com> wrote:
>
> Is it possible in Tapestry 5 to programatically change the locale for
> a sesison similar to IEngine.setLocale() from Tapestry 4?
>
> In my case I want to set the locale after the login into the
> application (locale is stored in the user profile) and not rely on the
> browser locale.
>
> Thank you,
>
> Bogdan Calmac.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 - Changing Locale

Posted by yosemite <km...@hotmail.com>.
Your code worked for me, except I replaced ThreadLocale by PersistentLocale

@Inject
@Service("PersistentLocale")
private PersistentLocale persistentLocaleService;

then it works using e.g.

persistentLocaleService.set(new Locale("fr"));

Karel


petros wrote:
> 
> tapestry version 5.0.4
> 
> I have the following code in the html template of my LayoutCmpnt
> <aa t:id="greekLocaleLink" t:type="ActionLink">Greek</aa><br/>
> <aa t:id="englishLocaleLink" t:type="ActionLink">English</aa>
> 
> and the following code in the LayoutCmpnt.java
> 	@Inject
> 	@Service("ThreadLocale")
> 	private ThreadLocale threadLocaleService;
> 	
> 	@Inject
> 	private Locale currentLocale; 
> 	
> 	@OnEvent(value = "action", component = "greekLocaleLink")
> 	Object onActionFromGreekLocaleLink()
> 	{
> 		threadLocaleService.setLocale(new Locale("el"));
> 		return null;
> 	}
> 	
> 	@OnEvent(value = "action", component = "englishLocaleLink")
> 	Object onActionFromEnglishLocaleLink()
> 	{
> 		threadLocaleService.setLocale(new Locale("en"));
> 		return null;
> 	}	
> 
> When the Greek link is clicked the onActionFromGreekLocaleLink() method is
> called as expected, but just before the method is returned the
> currentLocale object is still set to the "en" Locale. Is this the right
> way to change the Locale programmatically ?
> 
> Petros
> 
> 
> Howard Lewis Ship wrote:
>> 
>> I think that comment is out of date.
>> 
>> You should be able to inject the ThreadLocale service and change the
>> locale there.  Tapestry will pick up on that and write out an updated
>> cookie, which will cause the subsequent render request to be in the
>> new locale.
>> 
>> On 3/9/07, Bogdan Calmac <bc...@gmail.com> wrote:
>>> Thanks guys, I saw that, but there was no mention about the ability to
>>> change the locale at application level. So I can assume that for my
>>> use case I would inject a new service in my page and use it to change
>>> the locale programatically?
>>>
>>> Thanks,
>>>
>>> Bogdan Calmac.
>>>
>>> On 3/9/07, Hugo Palma <hu...@gmail.com> wrote:
>>> > Take a look at the bottom of this page
>>> >
>>> http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html.
>>> >
>>> > /"Tapestry does not yet support changing the locale, but that will be
>>> > available shortly."/
>>> >
>>> > Bogdan Calmac wrote:
>>> > > Is it possible in Tapestry 5 to programatically change the locale
>>> for
>>> > > a sesison similar to IEngine.setLocale() from Tapestry 4?
>>> > >
>>> > > In my case I want to set the locale after the login into the
>>> > > application (locale is stored in the user profile) and not rely on
>>> the
>>> > > browser locale.
>>> > >
>>> > > Thank you,
>>> > >
>>> > > Bogdan Calmac.
>>> > >
>>> > >
>>> ---------------------------------------------------------------------
>>> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> > > For additional commands, e-mail: users-help@tapestry.apache.org
>>> > >
>>> > >
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> 
>> 
>> -- 
>> Howard M. Lewis Ship
>> TWD Consulting, Inc.
>> Independent J2EE / Open-Source Java Consultant
>> Creator and PMC Chair, Apache Tapestry
>> Creator, Apache HiveMind
>> 
>> Professional Tapestry training, mentoring, support
>> and project work.  http://howardlewisship.com
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5---Changing-Locale-tf3376399.html#a11489178
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 - Changing Locale

Posted by petros <pe...@cypoz.com>.
tapestry version 5.0.4

I have the following code in the html template of my LayoutCmpnt
<aa t:id="greekLocaleLink" t:type="ActionLink">Greek</aa><br/>
<aa t:id="englishLocaleLink" t:type="ActionLink">English</aa>

and the following code in the LayoutCmpnt.java
	@Inject
	@Service("ThreadLocale")
	private ThreadLocale threadLocaleService;
	
	@Inject
	private Locale currentLocale; 
	
	@OnEvent(value = "action", component = "greekLocaleLink")
	Object onActionFromGreekLocaleLink()
	{
		threadLocaleService.setLocale(new Locale("el"));
		return null;
	}
	
	@OnEvent(value = "action", component = "englishLocaleLink")
	Object onActionFromEnglishLocaleLink()
	{
		threadLocaleService.setLocale(new Locale("en"));
		return null;
	}	

When the Greek link is clicked the onActionFromGreekLocaleLink() method is
called as expected, but just before the method is returned the currentLocale
object is still set to the "en" Locale. Is this the right way to change the
Locale programmatically ?

Petros


Howard Lewis Ship wrote:
> 
> I think that comment is out of date.
> 
> You should be able to inject the ThreadLocale service and change the
> locale there.  Tapestry will pick up on that and write out an updated
> cookie, which will cause the subsequent render request to be in the
> new locale.
> 
> On 3/9/07, Bogdan Calmac <bc...@gmail.com> wrote:
>> Thanks guys, I saw that, but there was no mention about the ability to
>> change the locale at application level. So I can assume that for my
>> use case I would inject a new service in my page and use it to change
>> the locale programatically?
>>
>> Thanks,
>>
>> Bogdan Calmac.
>>
>> On 3/9/07, Hugo Palma <hu...@gmail.com> wrote:
>> > Take a look at the bottom of this page
>> >
>> http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html.
>> >
>> > /"Tapestry does not yet support changing the locale, but that will be
>> > available shortly."/
>> >
>> > Bogdan Calmac wrote:
>> > > Is it possible in Tapestry 5 to programatically change the locale for
>> > > a sesison similar to IEngine.setLocale() from Tapestry 4?
>> > >
>> > > In my case I want to set the locale after the login into the
>> > > application (locale is stored in the user profile) and not rely on
>> the
>> > > browser locale.
>> > >
>> > > Thank you,
>> > >
>> > > Bogdan Calmac.
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > > For additional commands, e-mail: users-help@tapestry.apache.org
>> > >
>> > >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> Howard M. Lewis Ship
> TWD Consulting, Inc.
> Independent J2EE / Open-Source Java Consultant
> Creator and PMC Chair, Apache Tapestry
> Creator, Apache HiveMind
> 
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5---Changing-Locale-tf3376399.html#a10424282
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 - Changing Locale

Posted by petros <pe...@cypoz.com>.
I have the following link in my html tapestry page
<div t:id="englishLocaleLink" t:type="ActionLink">English</div>

and the following method in the corresponding Java Class but it doesn't get
called when the above link is clicked
	@OnEvent(value = "action", component = "englishLocaleLink")
	Object onActionFromEnglishLocaleLink(@InjectService("ThreadLocale")
ThreadLocale threadLocale)
	{		
		threadLocale.setLocale(new Locale("en"));
		return null;
	}

If I remove the ThreadLocale parameter the method gets called but obviously
the locale is not changed. 
Is the above the correct way to inject the ThreadLocale service in my page?
If yes then how can I force the above method to be called and consequently
change the locale. 

Thanks,
Petros


Howard Lewis Ship wrote:
> 
> I think that comment is out of date.
> 
> You should be able to inject the ThreadLocale service and change the
> locale there.  Tapestry will pick up on that and write out an updated
> cookie, which will cause the subsequent render request to be in the
> new locale.
> 
> On 3/9/07, Bogdan Calmac <bc...@gmail.com> wrote:
>> Thanks guys, I saw that, but there was no mention about the ability to
>> change the locale at application level. So I can assume that for my
>> use case I would inject a new service in my page and use it to change
>> the locale programatically?
>>
>> Thanks,
>>
>> Bogdan Calmac.
>>
>> On 3/9/07, Hugo Palma <hu...@gmail.com> wrote:
>> > Take a look at the bottom of this page
>> >
>> http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html.
>> >
>> > /"Tapestry does not yet support changing the locale, but that will be
>> > available shortly."/
>> >
>> > Bogdan Calmac wrote:
>> > > Is it possible in Tapestry 5 to programatically change the locale for
>> > > a sesison similar to IEngine.setLocale() from Tapestry 4?
>> > >
>> > > In my case I want to set the locale after the login into the
>> > > application (locale is stored in the user profile) and not rely on
>> the
>> > > browser locale.
>> > >
>> > > Thank you,
>> > >
>> > > Bogdan Calmac.
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > > For additional commands, e-mail: users-help@tapestry.apache.org
>> > >
>> > >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> Howard M. Lewis Ship
> TWD Consulting, Inc.
> Independent J2EE / Open-Source Java Consultant
> Creator and PMC Chair, Apache Tapestry
> Creator, Apache HiveMind
> 
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5---Changing-Locale-tf3376399.html#a10414090
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 - Changing Locale

Posted by Howard Lewis Ship <hl...@gmail.com>.
I think that comment is out of date.

You should be able to inject the ThreadLocale service and change the
locale there.  Tapestry will pick up on that and write out an updated
cookie, which will cause the subsequent render request to be in the
new locale.

On 3/9/07, Bogdan Calmac <bc...@gmail.com> wrote:
> Thanks guys, I saw that, but there was no mention about the ability to
> change the locale at application level. So I can assume that for my
> use case I would inject a new service in my page and use it to change
> the locale programatically?
>
> Thanks,
>
> Bogdan Calmac.
>
> On 3/9/07, Hugo Palma <hu...@gmail.com> wrote:
> > Take a look at the bottom of this page
> > http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html.
> >
> > /"Tapestry does not yet support changing the locale, but that will be
> > available shortly."/
> >
> > Bogdan Calmac wrote:
> > > Is it possible in Tapestry 5 to programatically change the locale for
> > > a sesison similar to IEngine.setLocale() from Tapestry 4?
> > >
> > > In my case I want to set the locale after the login into the
> > > application (locale is stored in the user profile) and not rely on the
> > > browser locale.
> > >
> > > Thank you,
> > >
> > > Bogdan Calmac.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

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


Re: T5 - Changing Locale

Posted by Bogdan Calmac <bc...@gmail.com>.
Thanks guys, I saw that, but there was no mention about the ability to
change the locale at application level. So I can assume that for my
use case I would inject a new service in my page and use it to change
the locale programatically?

Thanks,

Bogdan Calmac.

On 3/9/07, Hugo Palma <hu...@gmail.com> wrote:
> Take a look at the bottom of this page
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html.
>
> /"Tapestry does not yet support changing the locale, but that will be
> available shortly."/
>
> Bogdan Calmac wrote:
> > Is it possible in Tapestry 5 to programatically change the locale for
> > a sesison similar to IEngine.setLocale() from Tapestry 4?
> >
> > In my case I want to set the locale after the login into the
> > application (locale is stored in the user profile) and not rely on the
> > browser locale.
> >
> > Thank you,
> >
> > Bogdan Calmac.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>

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


Re: T5 - Changing Locale

Posted by Hugo Palma <hu...@gmail.com>.
Take a look at the bottom of this page 
http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html.

/"Tapestry does not yet support changing the locale, but that will be 
available shortly."/

Bogdan Calmac wrote:
> Is it possible in Tapestry 5 to programatically change the locale for
> a sesison similar to IEngine.setLocale() from Tapestry 4?
>
> In my case I want to set the locale after the login into the
> application (locale is stored in the user profile) and not rely on the
> browser locale.
>
> Thank you,
>
> Bogdan Calmac.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 - Changing Locale

Posted by Bogdan Calmac <bc...@gmail.com>.
I've been doing some other things, when I get a chance to try it, I'll
share the experience on the list.

Bogdan.

On 3/20/07, alexvs <th...@gmail.com> wrote:
>
> Hi Bogdan,
>
> Were you ever able to change the locale?
>
> Thanks!
>
> Alex
>
> Bogdan Calmac-4 wrote:
> >
> > Is it possible in Tapestry 5 to programatically change the locale for
> > a sesison similar to IEngine.setLocale() from Tapestry 4?
> >
> > In my case I want to set the locale after the login into the
> > application (locale is stored in the user profile) and not rely on the
> > browser locale.
> >
> > Thank you,
> >
> > Bogdan Calmac.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/T5---Changing-Locale-tf3376399.html#a9579521
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: T5 - Changing Locale

Posted by alexvs <th...@gmail.com>.
Hi Bogdan,

Were you ever able to change the locale?

Thanks!

Alex

Bogdan Calmac-4 wrote:
> 
> Is it possible in Tapestry 5 to programatically change the locale for
> a sesison similar to IEngine.setLocale() from Tapestry 4?
> 
> In my case I want to set the locale after the login into the
> application (locale is stored in the user profile) and not rely on the
> browser locale.
> 
> Thank you,
> 
> Bogdan Calmac.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5---Changing-Locale-tf3376399.html#a9579521
Sent from the Tapestry - User mailing list archive at Nabble.com.


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