Localizing numbers and dates
This section describes how to write and install a plug-in for doing your own localization of numbers and dates, if the facilities provided with the product are inadequate for your needs.
It is possible to define a localized numbering sequence for use by xsl:number and format-date(). This sequence will be used when you specify a
language in the lang attribute of the xsl:number element, or in the third
argument of the functions format-date(), format-time(), and
format-dateTime(). The feature is primarily intended to provide language-dependent
numbers and dates, but in fact it can be used to provide arbitrary numbering sequences.
To implement a numberer for language X, you need to define a class that implements the interface Numberer; usually it will be convenient to write the class as a subclass of the supplied AbstractNumberer, or if you want to use English as a fallback, the class Numberer_en which is itself a subclass of AbstractNumberer.
You can override any of the non-private methods in the base class, but the most useful ones to implement are the following:
|
Method |
Effect |
|
ordinalSuffix |
Supplies a suffix to be appended to a number to create the ordinal form, for example "1" becomes "1st" in English |
|
toWords |
Displays a number in words, in title case: for example "53" becomes "Fifty Three" in English |
|
toOrdinalWords |
Displays an ordinal number in words, in title case: for example "53" becomes "Fifty Third" in English |
|
monthName |
Displays the name of a month, optionally abbreviated |
|
dayName |
Displays the name of a day of the week, optionally abbreviated |
The class name can be anything you like, but by convention the Numberer for language LL is named
Numberer_LL.
There are two ways to register the numberer with the Saxon Configuration.
The first is to supply a LocalizerFactory that responds to the request for a particular
language, for example:
The alternative is to register the localization module in the configuration file.