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.

Reply via email to