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):
@Inject 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:
app_ja.properties app_en.properties
AppModule.java:
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:
@Inject private PersistentLocale persistentLocaleService; ... void onActionFromJaLocaleLink() { persistentLocaleService.set(Locale.JAPANESE); } void onActionFromEnLocaleLink() { persistentLocaleService.set(Locale.ENGLISH); }