<?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 2010-10-29T18:20:48.427+01:00--><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 <code>net.sf.saxon.number.Numberer_X</code>,
for example <code>net.sf.saxon.sort.Numberer_sv</code> for Swedish. This must implement the interface <code>Numberer</code>;
usually it will be convenient to write the class as a subclass of the supplied <code>AbstractNumberer</code>.
<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>Note that any hyphens in the language name are ignored in forming the class name, but case is significant.
For example if you specify <code>lang="en-GB"</code>, the Numberer must be named <code>net.sf.saxon.number.Numberer_enGB</code>.</p>
      <p><i>If you write a comprehensive Numberer for a particular language, please submit it, and I 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>