Skip to end of metadata
Go to start of metadata
Icon

This page is mostly a copy of the original corresponding Trails page and not ready for general inclusion to the public user guide for Tapestry-model

Customizing Tynamo internationalization

If you created your project with the supplied archetype, you already have it internationalized as a sample. You can click on the flags on the right corner to change the effective user locale and the resource bundles Tynamo uses to get the resources strings from. Just like other functionality in Tynamo, the framework makes assumptions on how you want to internationalize your application and the default don't always work for everybody. That's why you can override the internationalization functionality to your liking. Tynamo assumes localized resource bundles are named messages_LOCALE.properties and found in the classpath. You can change the way you want to choose the effective locale by customizing your Border component and/or provide a locale by some other means (for example, from a cookie value or as a URL parameter).

Localizing your application

Localized resources files are by default in src/main/resources/messages_LANG.properties. This version has already a pt (Portuguese) and en (English) version of this file. If you want to add a new language, copy the messages_en.properties to your new messages file (for example, messages_fr.properties for french) and edit the Borders.html, located in context/WEB-INF to provide a link to change the language (in the above example, a link to change it to French).

Localizing Entity names

You can add the fully qualified name of the entity Class as a property in the
property file:


You can also use the simple Class name (the entity name) as a property in the property file:


To localize the plural form of an entity name, add a resource key with __plural
to identify the resource key for a plural:


Localizing property names

You can use either the fully class name of an entity, adding the name of the property:


Or, you can use the property name alone:



Note that if you use a property name alone, the localized value is used for all matching property names regardless of the entity they are part of. This is usefull if you have a lot of properties with the same name in different entities (such as property "name"). Tynamo always searches first for the fully qualified name and secondly the property name alone.

Localizing error messages

To localize your error messages, you need to bind a validator annotation message to a resource key by supplying it as a parameter. The message must be enclosed in curly brackets "{keyname}" to denote a resource key. Otherwise, it will be used as-is as the error message.

For example, to localize a following validation pattern:

set the resource key in brackets as the message:

And naturally, you need to add a value for this resource key in the property file.

Localizing custom templates

For localize a custom template you have several options depending on the scope and size of the text you are localizing. For straight-forwarded localization of short strings on your page, you may use Tapestry l10n mechanism (as used in Tynamo default templates). The localized resource files are expected to be in a file name your_project_name_LANGUAGE.properties (located under context/your_project_name). For longer pure text pages - such as articles that don't necessarily have 1-1 translation in other locales, you may also supply links that resolve to physically different pages depending on the locale. And sometimes, you may also need to access the localized names of your entities and their properties, and display them elsewhere on the page.

As a quick Tapestry localization example, you would change the following code:

to:

And add yourkey in appname_LANGUAGE.properties file.

To access the localized names (displayNames) of your entities' properties somewhere else on the page, use an ognl expression to access the descriptors. Here's an example of getting the displayname of "instructions" property of the current model object:

Exception handling for missing resources

The displayed error depends on the case:

For missing Tapestry resources , the key will be displayed all in uppercase between "[]". For example, the key mykey will be displayed in the screen as "[MYKEY]".

For missing entity/property resources, if a key isn't found, the key will be displayed all in uppercase between "[TYNAMO][" and ]". For example, the key mykey will be displayed in the screen as "[TRAILS][MYKEY]".

If a resource key is used in Hibernate Validator but no corresponding resource is found, an exception is thrown. Tapestry will in turn handle that as any other uncaught exception and you'd see the Tapestry error page.

  • No labels

1 Comment

  1. The plural suffix is -plural not __plural in 0.1.0 version