You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Vinicius Carvalho <ja...@gmail.com> on 2005/06/26 23:23:02 UTC

Refreshing the engine's locale

Hello ppl. Once again here I am. As my presentation gets closer, I'd
like to have things shinning :D

I just implemented localization with Tapestry (It's so easy that I
can't even calculate the effort for doing it ).

Here's how I've done:

I have a LocaleChange Component with a listener:

public void changeLocale(IRequestCycle cycle){
		String language = (String)cycle.getServiceParameters()[0];
		String country = null;
		if(language.equals("pt")){
			country = "BR";
		}
		else
			country = "US";
		Locale locale = new Locale(language,country);
		getPage().getEngine().setLocale(locale);
		cycle.activate(getPage());
	}

<component id="brazil" type="DirectLink">
        <binding name="listener" expression="listeners.changeLocale"/>
		<static-binding name="parameters" value="pt"/>
    </component>
    <component id="us" type="DirectLink">
        <binding name="listener" expression="listeners.changeLocale"/>
		<static-binding name="parameters" value="en"/>
    </component>

    <context-asset name="brazilianFlag" path="images/brazil.gif"/>
   	<context-asset name="usFlag" path="images/usa.gif"/>

Due my high level of stupidity I did not figure out yet how to pass
more than one parameter using binding so I decided to do that ugly
trick (if-else).

It changes the locale, but the activate returns to the caller page
with the previous idiom. One must click in another page to see the
results. I thought that by forcing cycle.activate() that would be done
automatically.

Any ideas?

Thanks all

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


Re: Refreshing the engine's locale

Posted by Pablo Ruggia <pr...@gmail.com>.
The simplest way I know is to change the locale, and then throw a 
redirectexception to the page where you want to go. That will make the 
magic.

On 6/26/05, Vinicius Carvalho <ja...@gmail.com> wrote:
> 
> Hello ppl. Once again here I am. As my presentation gets closer, I'd
> like to have things shinning :D
> 
> I just implemented localization with Tapestry (It's so easy that I
> can't even calculate the effort for doing it ).
> 
> Here's how I've done:
> 
> I have a LocaleChange Component with a listener:
> 
> public void changeLocale(IRequestCycle cycle){
> String language = (String)cycle.getServiceParameters()[0];
> String country = null;
> if(language.equals("pt")){
> country = "BR";
> }
> else
> country = "US";
> Locale locale = new Locale(language,country);
> getPage().getEngine().setLocale(locale);
> cycle.activate(getPage());
> }
> 
> <component id="brazil" type="DirectLink">
> <binding name="listener" expression="listeners.changeLocale"/>
> <static-binding name="parameters" value="pt"/>
> </component>
> <component id="us" type="DirectLink">
> <binding name="listener" expression="listeners.changeLocale"/>
> <static-binding name="parameters" value="en"/>
> </component>
> 
> <context-asset name="brazilianFlag" path="images/brazil.gif"/>
> <context-asset name="usFlag" path="images/usa.gif"/>
> 
> Due my high level of stupidity I did not figure out yet how to pass
> more than one parameter using binding so I decided to do that ugly
> trick (if-else).
> 
> It changes the locale, but the activate returns to the caller page
> with the previous idiom. One must click in another page to see the
> results. I thought that by forcing cycle.activate() that would be done
> automatically.
> 
> Any ideas?
> 
> Thanks all
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

Re: Refreshing the engine's locale

Posted by Andreas Andreou <an...@di.uoa.gr>.
Vinicius Carvalho wrote:

>Hello ppl. Once again here I am. As my presentation gets closer, I'd
>like to have things shinning :D
>
>I just implemented localization with Tapestry (It's so easy that I
>can't even calculate the effort for doing it ).
>
>Here's how I've done:
>
>I have a LocaleChange Component with a listener:
>
>public void changeLocale(IRequestCycle cycle){
>		String language = (String)cycle.getServiceParameters()[0];
>		String country = null;
>		if(language.equals("pt")){
>			country = "BR";
>		}
>		else
>			country = "US";
>		Locale locale = new Locale(language,country);
>		getPage().getEngine().setLocale(locale);
>		cycle.activate(getPage());
>	}
>
><component id="brazil" type="DirectLink">
>        <binding name="listener" expression="listeners.changeLocale"/>
>		<static-binding name="parameters" value="pt"/>
>    </component>
>    <component id="us" type="DirectLink">
>        <binding name="listener" expression="listeners.changeLocale"/>
>		<static-binding name="parameters" value="en"/>
>    </component>
>
>    <context-asset name="brazilianFlag" path="images/brazil.gif"/>
>   	<context-asset name="usFlag" path="images/usa.gif"/>
>
>Due my high level of stupidity I did not figure out yet how to pass
>more than one parameter using binding so I decided to do that ugly
>trick (if-else).
>
>It changes the locale, but the activate returns to the caller page
>with the previous idiom. One must click in another page to see the
>results. I thought that by forcing cycle.activate() that would be done
>automatically.
>  
>
No, it's done done automatically. However, you can throw a
PageRedirectException and make it redirect to the current active page.
This will do the trick!

>Any ideas?
>
>Thanks all
>
>---------------------------------------------------------------------
>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