Contributing Translators

Here we create two Translators and make them available to the whole application by name.

Are you new to Tapestry?

(y, n, yes, no)

A price

(maximum 2 decimal places)

The first translator is called yesno and its class is YesNoTranslator.
It parses "y", "n", "yes", and "no" (ignoring case), client-side, to Boolean, server-side, and back to "yes" or "no", client-side.

The second translator is called money2 and its class is MoneyTranslator.
It parses a String, client-side, to a BigDecimal with maximum of 2 decimal places, server-side, and vice-versa.

We made both translators available to the whole application by contributing them to the TranslatorAlternatesSource
service - see AppModule source below.
Alternatively, a translator can be made available to the whole application and selected automatically based on the type
that it translates, by contributing it to the TranslatorSource service.

This example has also used localization, which is explained later in the Localization examples.