...
The PersistentLocale service can be used to programmatically override the locale for the current request. Note: You should be careful to only set the persistent locale to a supported locale.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Inject private PersistentLocale persistentLocale; void onActionFromLocaleToggle() { if ("en".equalsIgnoreCase(persistentLocale.get().getLanguage())) { persistentLocale.set(new Locale("de")); } else { persistentLocale.set(new Locale("en")); } return this; } public String getDisplayLanguage() { return persistentLocale.get().getDisplayLanguage(); } |
Once a persistent locale is set, you will see the locale name as the first virtual folder in page render and component event requests URLs. In this way, a persistent locale will, in fact, persist from request to request, or in a user's bookmarks.
You should be careful to only set the persistent locale to a supported locale.You will see the new locale take effect on the next request. If it is changed in a component event request (which is typical), the new locale will be used in the subsequent page render request.
Note that the locale for a page is fixed (it can't change once the page instance is created). In addition, a page may only be attached to a request once. In other words, if code in your page changes the persistent locale, you won't see a change to the page's locale (or localized messages) in that request.
Built-in Locales
While your application can support any locale (and thus any language) that you want, Tapestry provides only a limited set of translations for its own built-in messages. As of Tapestry 5.3, the following locales have translations provided:
en (English) | es (Spanish) | ja (Japanese) | ru (Russian) |
bg (Bulgarian) | fi (Finnish) | mk (Macedonian) | sr (Serbian) |
da (Danish) | fr (French) | nl (Dutch) | sv (Swedish) |
de (German) | hr (Croatian) | no (Norwegian) | zh (Chinese) |
el (Greek) | it (Italian) | pt (Portuguese) |
Providing translations for Tapestry built-in messages
Fortunately, Tapestry uses all the same mechanisms for its own locale support as it provides for your application. So, to support other locales, just translate the built-in message catalog (property) files yourself:
HTML |
---|
<style type="text/css">table.sectionMacro { width: auto; }</style>
|
Section | |||||||
---|---|---|---|---|---|---|---|
| |||||||
|
To have Tapestry use these new files, just put them in the corresponding package-named directory within your own app (for example, src/main/resources/org/apache/tapestry5/core.properties).
Finally, please open a new feature request here and attach the translated files so that they can be included in the next release of Tapestry.
Info |
---|
Please note that a patch is always preferred over an archive of properties files. |