You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Everton Agner <ev...@yahoo.com.br> on 2009/11/17 16:46:12 UTC
Dynamic Locale changing
To begin with... I am learning Tapestry from 1 month ago.
I am having problems with the Locale changing support in my application. To see the thing working, I hardcoded the language changing in the application (pt-BR and en support). Here's the code:
Page Template Code (only the necessary for the explanation)
<t:if test="localePortugueseBrazil">
<img src="${flagPortugueseBrazil}" style="margin: 3px;" />
<p:else>
<t:actionLink t:id="changeLocalePtBr" value="pt-BR">
<img src="${flagPortugueseBrazil}" title="${message:txt.change_locale.pt-BR}" style="margin: 3px;" />
</t:actionLink>
</p:else>
</t:if>
<t:if test="localeEnglishUSA">
<img src="${flagEnglishUSA}" style="margin: 3px;" />
<p:else>
<t:actionLink t:id="changeLocaleEnUs" value="en-US" >
<img src="${flagEnglishUSA}" title="${message:txt.change_locale.en-US}" style="margin: 3px;" />
</t:actionLink>
</p:else>
</t:if>
Page Class Code (there are actually the same localized methods/properties for the other language)
@Inject
private PersistentLocale persistentLocale;
@Inject
private Locale currentLocale;
@Inject
@Property
@Path("context:/layout/images/brazil.png")
private Asset flagBrazil;
@Inject
@Property
@Path("context:/layout/images/brazil_disabled.png")
private Asset flagBrazilDisabled;
public Asset getFlagPortugueseBrazil(){
if (!currentLocale.equals(new Locale("pt","BR"))){
return flagBrazil;
}else{
return flagBrazilDisabled;
}
}
public boolean isLocalePortugueseBrazil(){
if (currentLocale.equals(new Locale("pt","BR"))){
return true;
}else{
return false;
}
}
@OnEvent(component="changeLocalePtBr")
void changeLocalePtBr()
{
persistentLocale.set(new Locale("pt","BR"));
}
-----------
OK, it works perfectly... But now I want to turn this into a dynamic/extensible way... So, when adding a new Language Support, I only have to add it on the AppModule class (the SymbolConstants.SUPPORTED_LOCALES info), put the 2 images related to the language/country in the images folder (one image with colors and the other in black-white) and the text for ToolTip when the mouse is over the image.
So... The first thing I'm having problems with is to retrieve in Runtime the information stored on the AppModule class (contributeApplicationDefaults method). There is a way I can do this? If there isn't, is it good for me to have a config.properties file in the application so I can add the Supported Locales info there, and then retrieve it in the AppModule class to store in the contributeApplicationDefaults method?
The second problem I'm having is to retrieve the Assets (the images) in a Dynamic way (knowing the Locale name and if it's the enabled/disabled image)... I've read about AssetFactory, but didn't find any good example related.
I appreciate any help. :)
Everton Agner
____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com
Res: Dynamic Locale changing
Posted by Everton Agner <ev...@yahoo.com.br>.
Thanks Juan and Thiago!
It's exactly what I need for the Symbol retrieving :)
________________________________
De: Juan E. Maya <ma...@gmail.com>
Para: Tapestry users <us...@tapestry.apache.org>
Enviadas: Terça-feira, 17 de Novembro de 2009 16:10:20
Assunto: Re: Dynamic Locale changing
Sorry to interrupt :)
U can inject the supported languages by injecting the symbol in your layout.
Something like:
@Inject
@Symbol(SymbolConstants.SUPPORTED_LOCALES)
private String supportedLanguages;
Remember the languages are comma separated so just split them.
String[] languages = this.supportedLanguages.split(",");
with the language u can create the assets of the available locales
using the AssetFactory services and Resource classes.
On Tue, Nov 17, 2009 at 6:55 PM, Everton Agner
<ev...@yahoo.com.br> wrote:
> Thanks for the response!
>
> "Welcome to the Tapestry world! :)"
>
> My pleasure! The Framework is great! ;)
>
> Here's what I'm trying to do... In the Top of my page there will be a sequence of flags (the countries related to the supported languages of the app). Except for the Flag of the current country/language, all of them will be inside a <t:actionLink /> component to change the current Locale. The flag of the current country/language will not be inside a ActionLink, so only will be shown as it's "disabled version" (the same flag in black/white colors - another image).
>
> So, one of my problems is (was, after your answer :)) to retrieve the information of the Supported Languages in Runtime, and render it in the page (Layout component, to tell the truth) as a Sequence of flags enabling Language Change.
>
> If my problem was to show the Image of the current country/language, it would be easy as you said...
>
> Thanks for the Symbol value retrieving example!! I'll try here. :)
>
>
>
>
> ________________________________
> De: Thiago H. de Paula Figueiredo <th...@gmail.com>
> Para: Tapestry users <us...@tapestry.apache.org>
> Enviadas: Terça-feira, 17 de Novembro de 2009 15:39:32
> Assunto: Re: Dynamic Locale changing
>
> Em Tue, 17 Nov 2009 13:46:12 -0200, Everton Agner <ev...@yahoo.com.br> escreveu:
>
>> To begin with... I am learning Tapestry from 1 month ago.
>
> Welcome to the Tapestry world! :)
>
>> @Inject
>> @Property
>> @Path("context:/layout/images/brazil.png")
>> private Asset flagBrazil;
>
> You're doing it in a way more complex that it needs to be. All you need to do is to refer to your asset and the Tapestry automatically searches for the localized version. Example:
>
> @Inject
> @Property
> @Path("context:/layout/images/flag.png")
> private Asset flag;
>
> If the current locale is pt_BR, Tapestry will try to find /layout/images/flag_pt_BR.png in your context. If it's found, it will be used. ;)
>
>> So... The first thing I'm having problems with is to retrieve in Runtime the information stored on the AppModule class (contributeApplicationDefaults method). There is a way I can do this?
>
> Suppose you need to know the value of the tapestry.production-mode symbol. You can inject it in your component or page class:
>
> @Inject
> @Symbol("tapestry.production-mode")
> private boolean productionMode;
>
>> The second problem I'm having is to retrieve the Assets (the images) in a Dynamic way (knowing the Locale name and if it's the enabled/disabled image)... I've read about AssetFactory, but didn't find any good example related.
>
> You don't need to use AssetFactory to do that. Just name the assets appropriately. ;)
>
>
>
> ____________________________________________________________________________________
> Veja quais são os assuntos do momento no Yahoo! +Buscados
> http://br.maisbuscados.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com
Re: Dynamic Locale changing
Posted by "Juan E. Maya" <ma...@gmail.com>.
Sorry to interrupt :)
U can inject the supported languages by injecting the symbol in your layout.
Something like:
@Inject
@Symbol(SymbolConstants.SUPPORTED_LOCALES)
private String supportedLanguages;
Remember the languages are comma separated so just split them.
String[] languages = this.supportedLanguages.split(",");
with the language u can create the assets of the available locales
using the AssetFactory services and Resource classes.
On Tue, Nov 17, 2009 at 6:55 PM, Everton Agner
<ev...@yahoo.com.br> wrote:
> Thanks for the response!
>
> "Welcome to the Tapestry world! :)"
>
> My pleasure! The Framework is great! ;)
>
> Here's what I'm trying to do... In the Top of my page there will be a sequence of flags (the countries related to the supported languages of the app). Except for the Flag of the current country/language, all of them will be inside a <t:actionLink /> component to change the current Locale. The flag of the current country/language will not be inside a ActionLink, so only will be shown as it's "disabled version" (the same flag in black/white colors - another image).
>
> So, one of my problems is (was, after your answer :)) to retrieve the information of the Supported Languages in Runtime, and render it in the page (Layout component, to tell the truth) as a Sequence of flags enabling Language Change.
>
> If my problem was to show the Image of the current country/language, it would be easy as you said...
>
> Thanks for the Symbol value retrieving example!! I'll try here. :)
>
>
>
>
> ________________________________
> De: Thiago H. de Paula Figueiredo <th...@gmail.com>
> Para: Tapestry users <us...@tapestry.apache.org>
> Enviadas: Terça-feira, 17 de Novembro de 2009 15:39:32
> Assunto: Re: Dynamic Locale changing
>
> Em Tue, 17 Nov 2009 13:46:12 -0200, Everton Agner <ev...@yahoo.com.br> escreveu:
>
>> To begin with... I am learning Tapestry from 1 month ago.
>
> Welcome to the Tapestry world! :)
>
>> @Inject
>> @Property
>> @Path("context:/layout/images/brazil.png")
>> private Asset flagBrazil;
>
> You're doing it in a way more complex that it needs to be. All you need to do is to refer to your asset and the Tapestry automatically searches for the localized version. Example:
>
> @Inject
> @Property
> @Path("context:/layout/images/flag.png")
> private Asset flag;
>
> If the current locale is pt_BR, Tapestry will try to find /layout/images/flag_pt_BR.png in your context. If it's found, it will be used. ;)
>
>> So... The first thing I'm having problems with is to retrieve in Runtime the information stored on the AppModule class (contributeApplicationDefaults method). There is a way I can do this?
>
> Suppose you need to know the value of the tapestry.production-mode symbol. You can inject it in your component or page class:
>
> @Inject
> @Symbol("tapestry.production-mode")
> private boolean productionMode;
>
>> The second problem I'm having is to retrieve the Assets (the images) in a Dynamic way (knowing the Locale name and if it's the enabled/disabled image)... I've read about AssetFactory, but didn't find any good example related.
>
> You don't need to use AssetFactory to do that. Just name the assets appropriately. ;)
>
>
>
> ____________________________________________________________________________________
> Veja quais são os assuntos do momento no Yahoo! +Buscados
> http://br.maisbuscados.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Res: Dynamic Locale changing
Posted by Everton Agner <ev...@yahoo.com.br>.
Thanks for the response!
"Welcome to the Tapestry world! :)"
My pleasure! The Framework is great! ;)
Here's what I'm trying to do... In the Top of my page there will be a sequence of flags (the countries related to the supported languages of the app). Except for the Flag of the current country/language, all of them will be inside a <t:actionLink /> component to change the current Locale. The flag of the current country/language will not be inside a ActionLink, so only will be shown as it's "disabled version" (the same flag in black/white colors - another image).
So, one of my problems is (was, after your answer :)) to retrieve the information of the Supported Languages in Runtime, and render it in the page (Layout component, to tell the truth) as a Sequence of flags enabling Language Change.
If my problem was to show the Image of the current country/language, it would be easy as you said...
Thanks for the Symbol value retrieving example!! I'll try here. :)
________________________________
De: Thiago H. de Paula Figueiredo <th...@gmail.com>
Para: Tapestry users <us...@tapestry.apache.org>
Enviadas: Terça-feira, 17 de Novembro de 2009 15:39:32
Assunto: Re: Dynamic Locale changing
Em Tue, 17 Nov 2009 13:46:12 -0200, Everton Agner <ev...@yahoo.com.br> escreveu:
> To begin with... I am learning Tapestry from 1 month ago.
Welcome to the Tapestry world! :)
> @Inject
> @Property
> @Path("context:/layout/images/brazil.png")
> private Asset flagBrazil;
You're doing it in a way more complex that it needs to be. All you need to do is to refer to your asset and the Tapestry automatically searches for the localized version. Example:
@Inject
@Property
@Path("context:/layout/images/flag.png")
private Asset flag;
If the current locale is pt_BR, Tapestry will try to find /layout/images/flag_pt_BR.png in your context. If it's found, it will be used. ;)
> So... The first thing I'm having problems with is to retrieve in Runtime the information stored on the AppModule class (contributeApplicationDefaults method). There is a way I can do this?
Suppose you need to know the value of the tapestry.production-mode symbol. You can inject it in your component or page class:
@Inject
@Symbol("tapestry.production-mode")
private boolean productionMode;
> The second problem I'm having is to retrieve the Assets (the images) in a Dynamic way (knowing the Locale name and if it's the enabled/disabled image)... I've read about AssetFactory, but didn't find any good example related.
You don't need to use AssetFactory to do that. Just name the assets appropriately. ;)
____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com
Re: Dynamic Locale changing
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 17 Nov 2009 13:46:12 -0200, Everton Agner
<ev...@yahoo.com.br> escreveu:
> To begin with... I am learning Tapestry from 1 month ago.
Welcome to the Tapestry world! :)
> @Inject
> @Property
> @Path("context:/layout/images/brazil.png")
> private Asset flagBrazil;
You're doing it in a way more complex that it needs to be. All you need to
do is to refer to your asset and the Tapestry automatically searches for
the localized version. Example:
@Inject
@Property
@Path("context:/layout/images/flag.png")
private Asset flag;
If the current locale is pt_BR, Tapestry will try to find
/layout/images/flag_pt_BR.png in your context. If it's found, it will be
used. ;)
> So... The first thing I'm having problems with is to retrieve in Runtime
> the information stored on the AppModule class
> (contributeApplicationDefaults method). There is a way I can do this?
Suppose you need to know the value of the tapestry.production-mode symbol.
You can inject it in your component or page class:
@Inject
@Symbol("tapestry.production-mode")
private boolean productionMode;
> The second problem I'm having is to retrieve the Assets (the images) in
> a Dynamic way (knowing the Locale name and if it's the enabled/disabled
> image)... I've read about AssetFactory, but didn't find any good example
> related.
You don't need to use AssetFactory to do that. Just name the assets
appropriately. ;)
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org