You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sergueï Cambour <s....@gmail.com> on 2011/12/22 11:43:25 UTC
How to remove a locale prefix from url
I can't figure out how to remove the locale prefix from the url on Tapestry
5.1.
Every time when switching the locale, the url changed as follows:
my_host/en/home
or
my_host/fr/home
I fond that it is possible to add the following in the AppModule class:
public static void
contributeApplicationDefaults(MappedConfiguration<String, String>
configuration) {
configuration.add(SymbolConstants.ENCODE_LOCALE_INTO_PATH, "false");
}
coupled with LinkCreationListener2 (in the same AppModule class):
public LinkCreationListener2 buildLinkCreationListener(LinkCreationHub hub)
{
LinkCreationListener2 listener = new AppLinkCreationListenerImpl();
hub.addListener(listener);
return listener;
}
But how should I use AppLinkCreationListenerImpl ? I found on the net an
example but it does nothing, my local does not switch any more:
public class AppLinkCreationListenerImpl implements LinkCreationListener2
{
public void createdComponentEventLink(Link link,
ComponentEventRequestParameters params) {
link.addParameter("locale", String.valueOf(System.currentTimeMillis()));
}
public void createdPageRenderLink(Link link,
PageRenderRequestParameters params) {
link.addParameter("locale", String.valueOf(System.currentTimeMillis()));
}
}
Before that, I used PersistentLocale technic:
//in my Header class
@Inject
private PersistentLocale persistentLocale;
@Inject
private Locale currentLocale;
@Persist
private String localeLabel;
public String getLocaleLabel() {
if (localeLabel == null) {
if (currentLocale.equals(Locale.FRENCH)) {
localeLabel = new Locale("en").getDisplayName(Locale.ENGLISH);
} else {
localeLabel = new Locale("fr").getDisplayName(Locale.FRENCH);
}
}
return localeLabel;
}
@OnEvent(component = "switchlocale")
void changeLocale() {
localeLabel = currentLocale.getDisplayName(currentLocale);
if (currentLocale.equals(Locale.FRENCH)) {
persistentLocale.set(Locale.ENGLISH);
} else {
persistentLocale.set(Locale.FRENCH);
}
}
Any idea? Thanks.
Re: How to remove a locale prefix from url
Posted by Javix <s....@gmail.com>.
I discovered that in the real application that was made in one only
language(the client' one), there is a URLRewriterRule with
SimpleRequestWrapper in use. So I have to change a little bit my question:
what is the best way to implement the possibility to swith between locales
in this case taking in account that there should be 3 locales available for
the application (en, fr, de)? Thanks.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-a-locale-prefix-from-url-tp5094297p5119186.html
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