|
Localization
for more about localization see http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html Localization in Tapestry 5Localization is all about getting the right text to the user, in the right language. Localization support is well integrated into Tapestry. Tapestry allows you to easily separate the text you present to your users from the rest of your application ... pull it out of your Java code and even out of your component templates. You can then translate your messages into other languages and let Tapestry put everything together. Hints & TipsHow To Support New Languages ?
public static void contributeApplicationDefaults(
MappedConfiguration<String, String> configuration) {
configuration.add("tapestry.supported-locales", "en,fa,fr");
}this example tells that three locales -English(en) , Persian(fa) and French(fr)- most be supported by application. Page and Component Message Catalog
Each component and page may have a message catalog. A message catalog is a set of property files (PageName.properties, PageName_fr.properties...). These property files are the same format used by java.util.ResourceBundle, just lines of key=value. These files are packaged with the component's pages HTML template. note that message catalog name most be its page or component name Application Message Catalog
Individual pages and components can override the values defined in this message catalog. in other word if you used a message in a component, Tapestry will search Component Message Catalog, Components Parent Message Catalog, Page Message Catalog and Application Message Catalog respectively for resolve message value. How To Localize Validation Messages ?
if you want to put this message catalog in other package you most add following code to contribute application validation messages source : public void contributeValidationMessagesSource(Configuration<String> configuration) {
configuration.add("path/to/your/package/ValidationMessages.properties");
}How To Access Messages From Templates ?
<input type="submit" value="${message:save}"/>
...
<h1>${message:welcome}</h1>How To Switch Between Application Locales ?
here is a example of changing locale with PersistentLocale :
for more about localization see http://tapestry.apache.org/tapestry5/tapestry-core/guide/localization.html good luck. |
► Sign in to add a comment
How do you overwrite the Locale inside AppModule?? E.g. assigning different locales to domain names or subdomains ?
How can you access PersistentLocale? from inside the AppModule??
Please note that the ValidationMessages?.properties file should be in the package org.apache.tapestry5.internal and not org.apache.tapestry.internal (tapestry5 instead of just tapestry).
Hi, I've been trying to create an example to switch between languages in Tapestry 5. I've used the code above and got a NuulPointerException?. did I miss something? by the way, I am new to Tapestry 5.
Thank you Mohamed Omar
Great documentation
How to avois adding locale prefix in the URL like http://host/fr/home or http://host/en/home ? I found that I should 'add configuration.add(SymbolConstants?.ENCODE_LOCALE_INTO_PATH, "false");' to the AppModule? class and use LinkCreationListener2? or LinkCreationListener?(if Tapestry < 5.2.). But how?