Tapestry stores the locale of the current user in the ThreadLocale service. This locale is either determined by the HTTP header "Accept-Language" or the cookie "org.apache.tapestry.locale" (both sent by the browser). The cookie has precedence.

For changing the locale you have to use the PersistentLocale service and (re-)set the locale.

Here is an example with an ActionLink with the id "changeLocale" (the language comes as the context):

private PersistentLocale persistentLocale;

public void onActionFromChangeLocale(String language)
        persistentLocale.set(new Locale(language));

See also T5 Localization Guide

Nick Westgate also contributed the following snippet to the mailing list:

Create two property files:



    configuration.add("tapestry.supported-locales", "en,ja");

Page.html with two action links to select your locale (Japanese or English):

    <a t:type="ActionLink" t:id="jaLocaleLink" href="#">Japanese</a><br/>
    <a t:type="ActionLink" t:id="enLocaleLink" href="#">English</a><br/>

Page.java contains the event handlers to switch the locale:

    private PersistentLocale persistentLocaleService;


    void onActionFromJaLocaleLink()

    void onActionFromEnLocaleLink()

Tapestry5HowToChangeLocale (last edited 2009-09-20 23:20:03 by localhost)