home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Numbers / Words / lang.nl.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  8.9 KB  |  325 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  3. //
  4. // +----------------------------------------------------------------------+
  5. // | PHP version 4                                                        |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2003 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 3.0 of the PHP license,       |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/3_0.txt.                                  |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Authors: Piotr Klaban <makler@man.torun.pl>                          |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: lang.nl.php,v 1.1 2006/06/13 11:28:32 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Dutch language.
  23. //
  24.  
  25. /**
  26.  *
  27.  * Class for translating numbers into Dutch.
  28.  * @author Piotr Klaban
  29.  * @author WHAM van Dinter (for Dutch Translations)
  30.  * @package Numbers_Words
  31.  */
  32.  
  33. /**
  34.  * Include needed files
  35.  */
  36. require_once("Numbers/Words.php");
  37.  
  38. /**
  39.  * Class for translating numbers into Dutch.
  40.  *
  41.  * @author Piotr Klaban
  42.  * @author WHAM van Dinter (for Dutch Translations)
  43.  * @package Numbers_Words
  44.  */
  45. class Numbers_Words_nl extends Numbers_Words
  46. {
  47.  
  48.     // {{{ properties
  49.  
  50.     /**
  51.      * Locale name
  52.      * @var string
  53.      * @access public
  54.      */
  55.     var $locale      = 'nl';
  56.  
  57.     /**
  58.      * Language name in English
  59.      * @var string
  60.      * @access public
  61.      */
  62.     var $lang        = 'Dutch';
  63.  
  64.     /**
  65.      * Native language name
  66.      * @var string
  67.      * @access public
  68.      */
  69.     var $lang_native = 'Nederlands';
  70.  
  71.     /**
  72.      * The word for the minus sign
  73.      * @var string
  74.      * @access private
  75.      */
  76.     var $_minus = 'Minus'; // minus sign
  77.  
  78.     /**
  79.      * The sufixes for exponents (singular and plural)
  80.      * Names partly based on:
  81.      * http://nl.wikipedia.org/wiki/Quadriljoen
  82.      * @var array
  83.      * @access private
  84.      */
  85.     var $_exponent = array(
  86.         0 => array(''),
  87.         3 => array('Duizend','Duizend'),
  88.         6 => array('Miljoen','Miljoen'),
  89.         9 => array('Miljard','Miljard'),
  90.        12 => array('Biljoen','Biljoen'),
  91.        15 => array('Biljard','Biljard'),
  92.        18 => array('Triljoen','Triljoen'),
  93.        21 => array('Triljard','Triljard'),
  94.        24 => array('Quadriljoen','Quadriljoen'),
  95.        27 => array('Quadriljard','Quadriljard'),
  96.        30 => array('Quintiljoen','Quintiljoen'),
  97.        33 => array('Quintiljard','Quintiljard'),
  98.        36 => array('Sextiljoen','Sextiljoen'),
  99.        39 => array('Sextiljard','Sextiljard'),
  100.        42 => array('Septiljoen','Septiljoen'),
  101.        45 => array('Septiljard','Septiljard'),
  102.        48 => array('Octiljoen','Octiljoen'),
  103.        51 => array('Octiljard','Octiljard'),
  104.        54 => array('Noniljoen','Noniljoen'),
  105.        57 => array('Noniljard','Noniljard'),
  106.        60 => array('Deciljoen','Deciljoen'),
  107.        63 => array('Deciljard','Deciljard'),
  108.        66 => array('Undeciljoen','Undeciljoen'),
  109.        69 => array('Undeciljard','Undeciljard'),
  110.        72 => array('Duodeciljoen','Duodeciljoen'),
  111.        75 => array('Duodeciljard','Duodeciljard'),
  112.        78 => array('Tredeciljoen','Tredeciljoen'),
  113.        81 => array('Tredeciljard','Tredeciljard'),
  114.       120 => array('Vigintiljoen','Vigintiljoen'),
  115.       123 => array('Vigintiljard','Vigintiljard'),
  116.       600 => array('Zentiljoen','Zentiljoen'), // oder Centillion
  117.       603 => array('Zentiljardn','Zentiljard')
  118.         );
  119.  
  120.     /**
  121.      * The array containing the digits (indexed by the digits themselves).
  122.      * @var array
  123.      * @access private
  124.      */
  125.     var $_digits = array(
  126.         0 => 'nul', 'een', 'twee', 'drie', 'vier',
  127.         'vijf', 'zes', 'zeven', 'acht', 'negen'
  128.     );
  129.  
  130.     /**
  131.      * The word separator
  132.      * @var string
  133.      * @access private
  134.      */
  135.     var $_sep  = '';
  136.  
  137.     /**
  138.      * The exponent word separator
  139.      * @var string
  140.      * @access private
  141.      */
  142.     var $_sep2 = '-';
  143.  
  144.     // }}}
  145.     // {{{ toWords()
  146.  
  147.     /**
  148.      * Converts a number to its word representation
  149.      * in Dutch language.
  150.      *
  151.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  152.      *                        that need to be converted to words
  153.      * @param  integer $power The power of ten for the rest of the number to the right.
  154.      *                        Optional, defaults to 0.
  155.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  156.      *                        Used internally. Optional, defaults to ''.
  157.      *
  158.      * @return string  The corresponding word representation
  159.      *
  160.      * @access private
  161.      * @author Piotr Klaban <makler@man.torun.pl>
  162.      * @author WHAM van Dinter <willem@fkkc.nl>
  163.      * @since  PHP 4.2.3
  164.      */
  165.     function toWords($num, $power = 0, $powsuffix = '') {
  166.       $ret = '';
  167.  
  168.       // add a minus sign
  169.       if (substr($num, 0, 1) == '-') {
  170.         $ret = $this->_sep . $this->_minus;
  171.         $num = substr($num, 1);
  172.       }
  173.  
  174.       // strip excessive zero signs and spaces
  175.       $num = trim($num);
  176.       $num = preg_replace('/^0+/','',$num);
  177.  
  178.       if (strlen($num) > 3) {
  179.           $maxp = strlen($num)-1;
  180.           $curp = $maxp;
  181.           for ($p = $maxp; $p > 0; --$p) { // power
  182.  
  183.             // check for highest power
  184.             if (isset($this->_exponent[$p])) {
  185.               // send substr from $curp to $p
  186.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  187.               $snum = preg_replace('/^0+/','',$snum);
  188.               if ($snum !== '') {
  189.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  190.                   if ($powsuffix != '')
  191.                     $cursuffix .= $this->_sep . $powsuffix;
  192.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  193.               }
  194.               $curp = $p - 1;
  195.               continue;
  196.             }
  197.           }
  198.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  199.           if ($num == 0) {
  200.               return $ret;
  201.           }
  202.       } elseif ($num == 0 || $num == '') {
  203.         return $this->_sep . $this->_digits[0];
  204.       }
  205.  
  206.       $h = $t = $d = 0;
  207.  
  208.       switch(strlen($num)) {
  209.         case 3:
  210.           $h = (int)substr($num,-3,1);
  211.  
  212.         case 2:
  213.           $t = (int)substr($num,-2,1);
  214.  
  215.         case 1:
  216.           $d = (int)substr($num,-1,1);
  217.           break;
  218.  
  219.         case 0:
  220.           return;
  221.           break;
  222.       }
  223.  
  224.       if ($h) {
  225.  
  226.         $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'honderd';
  227.       }
  228.  
  229.       if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
  230.         if ($t > 0) {
  231.           $ret .= $this->_digits[$d] . 'en';
  232.         } else {
  233.           $ret .= $this->_digits[$d];
  234.           if ($d == 1)
  235.             if ($power == 0) {
  236.               $ret .= 's'; // fuer eins
  237.             } else {
  238.               if ($power != 3) {  // tausend ausnehmen
  239.                 $ret .= ''; // fuer eine
  240.               }
  241.             }
  242.         }
  243.       }
  244.  
  245.       // ten, twenty etc.
  246.       switch ($t) {
  247.       case 9:
  248.       case 8:
  249.       case 7:
  250.       case 6:
  251.       case 5:
  252.           $ret .= $this->_sep . $this->_digits[$t] . 'tig';
  253.           break;
  254.  
  255.       case 4:
  256.           $ret .= $this->_sep . 'veertig';
  257.           break;
  258.  
  259.       case 3:
  260.           $ret .= $this->_sep . 'dertig';
  261.           break;
  262.  
  263.       case 2:
  264.           $ret .= $this->_sep . 'twintig';
  265.           break;
  266.  
  267.       case 1:
  268.           switch ($d) {
  269.           case 0:
  270.               $ret .= $this->_sep . 'tien';
  271.               break;
  272.  
  273.           case 1:
  274.               $ret .= $this->_sep . 'elf';
  275.               break;
  276.  
  277.           case 2:
  278.               $ret .= $this->_sep . 'twaalf';
  279.               break;
  280.  
  281.           case 3:
  282.               $ret .= $this->_sep . 'dertien';
  283.               break;
  284.  
  285.           case 4:
  286.               $ret .= $this->_sep . 'veertien';
  287.               break;
  288.  
  289.           case 5:
  290.           case 6:
  291.           case 7:
  292.           case 8:
  293.           case 9:
  294.               $ret .= $this->_sep . $this->_digits[$d] . 'tien';
  295.               break;
  296.  
  297.           }
  298.           break;
  299.       }
  300.  
  301.       if ($power > 0) {
  302.         if (isset($this->_exponent[$power]))
  303.           $lev = $this->_exponent[$power];
  304.  
  305.         if (!isset($lev) || !is_array($lev))
  306.           return null;
  307.  
  308.         if ($power == 3)
  309.           $ret .= $this->_sep . $lev[0];
  310.         elseif ($d == 1 && ($t+$h) == 0)
  311.           $ret .= $this->_sep2 . $lev[0] . $this->_sep2;
  312.         else
  313.           $ret .= $this->_sep2 . $lev[1] . $this->_sep2;
  314.       }
  315.  
  316.       if ($powsuffix != '')
  317.         $ret .= $this->_sep . $powsuffix;
  318.  
  319.       return $ret;
  320.     }
  321.     // }}}
  322. }
  323.  
  324. ?>
  325.