<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensibility" page="localizing" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Localizing numbers and dates</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Localizing numbers and dates"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Localizing numbers and dates</h1>
      <p>It is possible to define a localized numbering sequence for use by 
         <code>xsl:number</code> and <code>format-date()</code>. 
This sequence will be used when you specify a language in the <code>lang</code>
attribute of the <code>xsl:number</code> element, or in the third argument of the functions
<code>format-date()</code>, <code>format-time()</code>, and <code>format-dateTime()</code>.
 The feature is primarily intended to provide language-dependent numbers and dates,
but in fact it can be used to provide arbitrary numbering sequences.</p>
      <p>To implement a numberer for language X, you need to define a class that implements the interface 
        <a class="bodylink" href="../javadoc/net/sf/saxon/lib/Numberer.html"><code>Numberer</code></a>;
usually it will be convenient to write the class as a subclass of the supplied <a class="bodylink" href="../javadoc/net/sf/saxon/number/AbstractNumberer.html"><code>AbstractNumberer</code></a>.
<code>Numberer</code> implementations are supplied for a number of languages, 
and you can use these as a prototype to write your own.</p>
      <p>The languages supplied with the product are:</p>
      <table>
         <tr>
            <td content="para">
               <p>code</p>
            </td>
            <td content="para">
               <p>Language</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>da</p>
            </td>
            <td content="para">
               <p>Danish</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>de</p>
            </td>
            <td content="para">
               <p>German</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>en</p>
            </td>
            <td content="para">
               <p>English</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>fr</p>
            </td>
            <td content="para">
               <p>French</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>fr-BE</p>
            </td>
            <td content="para">
               <p>French (Belgium)</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>it</p>
            </td>
            <td content="para">
               <p>Italian</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>nl</p>
            </td>
            <td content="para">
               <p>Dutch</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>nl-BE</p>
            </td>
            <td content="para">
               <p>Flemish (Belgium)</p>
            </td>
         </tr>
         <tr>
            <td content="para">
               <p>sv</p>
            </td>
            <td content="para">
               <p>Swedish</p>
            </td>
         </tr>
      </table>
      <p>The numbering sequence for English is used by default if no other can be loaded.</p>
      <p>Normally your localization class will extend the class <code>AbstractNumberer</code> so that you can reuse functionality like roman
numerals which do not need to be localized. Alternatively, if you only want to modify the existing English localization, you could
choose to implement a subclass of <code>Numberer_en</code>.</p>
      <p>You can override any of the non-private methods in the base class, but the most useful ones to implement are 
the following:</p>
      <table>
         <thead>
            <tr>
               <td content="para">
                  <p>Method</p>
               </td>
               <td content="para">
                  <p>Effect</p>
               </td>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td content="para">
                  <p>ordinalSuffix</p>
               </td>
               <td content="para">
                  <p>Supplies a suffix to be appended to a number to create the ordinal form,
for example "1" becomes "1st" in English</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>toWords</p>
               </td>
               <td content="para">
                  <p>Displays a number in words, in title case: 
for example "53" becomes "Fifty Three" in English</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>toOrdinalWords</p>
               </td>
               <td content="para">
                  <p>Displays an ordinal number in words, in title case: 
for example "53" becomes "Fifty Third" in English</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>monthName</p>
               </td>
               <td content="para">
                  <p>Displays the name of a month, optionally abbreviated</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>dayName</p>
               </td>
               <td content="para">
                  <p>Displays the name of a day of the week, optionally abbreviated</p>
               </td>
            </tr>
         </tbody>
      </table>
      <p>The class name can be anything you like, but by convention the Numberer for language LL is named 
        <code>net.sf.saxon.number.Numberer_LL</code>.</p>
      <p>The way that the numberer is registered with the Saxon Configuration differs between Saxon-HE on the one hand,
        and Saxon-PE/EE on the other. On Saxon-HE, you need to supply a <code>LocalizerFactory</code> that responds the
        request for a particular language: for example:</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
Configuration config = new Configuration();
config.setLocalizerFactory(new LocalizerFactory() {
  public Numberer getNumberer(String language, String country) {
    if (language.equals("jp")) {
      return Numberer_JP.getInstance();
    } else {
      return null;
    }
  }
});</code>
         </pre>
      </div>
      <p>You can also use this mechanism on Saxon-PE/HE, but an alternative is to register the localization module
        in the <a class="bodylink" href="../configuration/configuration-file.xml">configuration file</a>.</p>
      <p><i>If you write a comprehensive <code>Numberer</code> for a particular language, please submit it, 
         and we will be happy to include it in future
versions of the product as an open-source component. You must agree to release it under the Mozilla Public License or under
any other recognized open source license that Saxon might adopt in the future.</i></p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="uri-resolver.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>