Customize the behavior of a formatting method

You can customize formatting behavior by passing your own formatter classes into a LocalizableTextFormatter instance through an array of optional values. This enables you to take variables other than locale and time zone into account when formatting localized text.

Perform the following steps to customize the behavior of a formatting method:

  1. Write your own formatter class.

    For more information about implementation, see LocalizableTextFormatter class.

  2. In the application code, create an instance of your formatter class as appropriate, and pass it with any other optional localization values into an instance of LocalizableTextFormatter.

    When the LocalizableTextFormatter instance reads the instance that has been passed in, it attempts to call format() on the passed in instance. The string returned is then processed with any other elements in the array.

Example: Customize a formatting method

The localizable-text package provides an example of a user-defined class, called LocalizableTextDateTimeArgument. This class enables date and time information to be selectively formatted according to the style values defined in java.text.DateFormat as well as constants defined within LocalizableTextDateTimeArgument itself.