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.it_IT.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  10.0 KB  |  349 lines

  1. <?php
  2. /* vim: set expandtab tabstop=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: Filippo Beltramini, Davide Caironi                          |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // Numbers_Words class extension to spell numbers in Italian.
  21. //
  22.  
  23. /**
  24.  * Class for translating numbers into Italian.
  25.  *
  26.  * @author Filippo Beltramini <phil@esight.it>
  27.  * @author Davide Caironi     <cairo@esight.it>
  28.  * @package Numbers_Words
  29.  */
  30.  
  31. /**
  32.  * Include needed files
  33.  */
  34. require_once("Numbers/Words.php");
  35.  
  36. /**
  37.  * Class for translating numbers into Italian.
  38.  * It supports up to quadrilions
  39.  *
  40.  * @author Filippo Beltramini <phil@esight.it>
  41.  * @author Davide Caironi     <cairo@esight.it>
  42.  * @package Numbers_Words
  43.  */
  44. class Numbers_Words_it_IT extends Numbers_Words
  45. {
  46.     // {{{ properties
  47.  
  48.     /**
  49.      * Locale name
  50.      * @var string
  51.      * @access public
  52.      */
  53.     var $locale      = 'it_IT';
  54.     
  55.     /**
  56.      * Language name in English
  57.      * @var string
  58.      * @access public
  59.      */
  60.     var $lang        = 'Italian';
  61.     
  62.     /**
  63.      * Native language name
  64.      * @var string
  65.      * @access public
  66.      */
  67.     var $lang_native = 'Italiano';
  68.  
  69.     /**
  70.      * The word for the minus sign
  71.      * @var string
  72.      * @access private
  73.      */
  74.     var $_minus = 'meno ';
  75.  
  76.     /**
  77.      * The sufixes for exponents (singular and plural)
  78.      * @var array
  79.      * @access private
  80.      */
  81.     var $_exponent = array(
  82.         0 => array('',''),
  83.         3 => array('mille','mila'),
  84.         6 => array('milione','miloni'),
  85.        12 => array('miliardo','miliardi'),
  86.        18 => array('trillone','trilloni'),
  87.        24 => array('quadrilione','quadrilioni'),
  88.         );
  89.     /**
  90.      * The array containing the digits (indexed by the digits themselves).
  91.      * @var array
  92.      * @access private
  93.      */
  94.      var $_digits = array(
  95.       0 => 'zero', 'uno', 'due', 'tre', 'quattro',
  96.        'cinque', 'sei', 'sette', 'otto', 'nove'
  97.     );
  98.     
  99.     /**
  100.      * The word separator
  101.      * @var string
  102.      * @access private
  103.      */
  104.     var $_sep = '';
  105.     // }}}
  106.     // {{{ toWords()
  107.     /**
  108.      * Converts a number to its word representation
  109.      * in italiano.
  110.      *
  111.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  112.      *                        that should be converted to a words representation
  113.      * @param  integer $power The power of ten for the rest of the number to the right.
  114.      *                        For example toWords(12,3) should give "doce mil".
  115.      *                        Optional, defaults to 0.
  116.      * @return string  The corresponding word representation
  117.      *
  118.      * @access private
  119.      * @author Filippo Beltramini
  120.      * @since  PHP 4.2.3
  121.      */
  122.     function toWords($num, $power = 0)
  123.     {
  124.         // The return string;
  125.         $ret = '';
  126.  
  127.         // add a the word for the minus sign if necessary
  128.         if (substr($num, 0, 1) == '-')
  129.         {
  130.             $ret = $this->_sep . $this->_minus;
  131.             $num = substr($num, 1);
  132.         }
  133.  
  134.  
  135.         // strip excessive zero signs
  136.         $num = preg_replace('/^0+/','',$num);
  137.  
  138.         if (strlen($num) > 6)
  139.         {
  140.             $current_power = 6;
  141.             // check for highest power
  142.             if (isset($this->_exponent[$power]))
  143.             {
  144.                 // convert the number above the first 6 digits
  145.                 // with it's corresponding $power.
  146.                 $snum = substr($num, 0, -6);
  147.                 $snum = preg_replace('/^0+/','',$snum);
  148.                 if ($snum !== '') {
  149.                     $ret .= $this->toWords($snum, $power + 6);
  150.                 }
  151.             }
  152.             $num = substr($num, -6);
  153.             if ($num == 0) {
  154.                 return $ret;
  155.             }
  156.         }
  157.         elseif ($num == 0 || $num == '') {
  158.             return(' '.$this->_digits[0].' ');
  159.             $current_power = strlen($num);
  160.         }
  161.         else {
  162.             $current_power = strlen($num);
  163.         }
  164.  
  165.         // See if we need "thousands"
  166.         $thousands = floor($num / 1000);
  167.         if ($thousands == 1) {
  168.             $ret .= $this->_sep . 'mille' . $this->_sep;
  169.         }
  170.         elseif ($thousands > 1) {
  171.             $ret .= $this->toWords($thousands, 3) . $this->_sep;//. 'mil' . $this->_sep;
  172.         }
  173.  
  174.         // values for digits, tens and hundreds
  175.         $h = floor(($num / 100) % 10);
  176.         $t = floor(($num / 10) % 10);
  177.         $d = floor($num % 10);
  178.  
  179.         // centinaia: duecento, trecento, etc...
  180.         switch ($h)
  181.         {
  182.             case 1:
  183.                 if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
  184.                     $ret .= $this->_sep . 'cento';
  185.                 }
  186.                 else {
  187.                     $ret .= $this->_sep . 'cento';
  188.                 }
  189.                 break;
  190.             case 2:
  191.             case 3:
  192.             case 4:
  193.             case 6:
  194.             case 8:
  195.                 $ret .= $this->_sep . $this->_digits[$h] . 'cento';
  196.                 break;
  197.             case 5:
  198.                 $ret .= $this->_sep . 'cinquecento';
  199.                 break;
  200.             case 7:
  201.                 $ret .= $this->_sep . 'settecento';
  202.                 break;
  203.             case 9:
  204.                 $ret .= $this->_sep . 'novecento';
  205.                 break;
  206.         }
  207.  
  208.         // decine: venti trenta, etc...
  209.         switch ($t)
  210.         {
  211.             case 9:
  212.                 $ret .= $this->_sep . 'novanta';
  213.                 break;
  214.  
  215.             case 8:
  216.                 $ret .= $this->_sep . 'ottanta';
  217.                 break;
  218.  
  219.             case 7:
  220.                 $ret .= $this->_sep . 'settanta';
  221.                 break;
  222.  
  223.             case 6:
  224.                 $ret .= $this->_sep . 'sessanta';
  225.                 break;
  226.  
  227.             case 5:
  228.                 $ret .= $this->_sep . 'cinquanta';
  229.                 break;
  230.  
  231.             case 4:
  232.                 $ret .= $this->_sep . 'quaranta';
  233.                 break;
  234.  
  235.             case 3:
  236.                 $ret .= $this->_sep . 'trenta';
  237.                 break;
  238.  
  239.             case 2:
  240.                 if ($d == 0) {
  241.                     $ret .= $this->_sep . 'venti';
  242.                 }
  243.                 else {
  244.                     if (($power > 0) and ($d == 1)) {
  245.                         $ret .= $this->_sep . 'ventuno';
  246.                     }
  247.                     else {
  248.                         $ret .= $this->_sep . 'venti' . $this->_digits[$d];
  249.                     }
  250.                 }
  251.                 break;
  252.  
  253.             case 1:
  254.                 switch ($d)
  255.                 {
  256.                     case 0:
  257.                         $ret .= $this->_sep . 'dieci';
  258.                         break;
  259.  
  260.                     case 1:
  261.                         $ret .= $this->_sep . 'undici';
  262.                         break;
  263.  
  264.                     case 2:
  265.                         $ret .= $this->_sep . 'dodici';
  266.                         break;
  267.  
  268.                     case 3:
  269.                         $ret .= $this->_sep . 'tredici';
  270.                         break;
  271.  
  272.                     case 4:
  273.                         $ret .= $this->_sep . 'quattordici';
  274.                         break;
  275.  
  276.                     case 5:
  277.                         $ret .= $this->_sep . 'quindici';
  278.                         break;
  279.  
  280.                     case 6:
  281.                          $ret .= $this->_sep . 'sedici';
  282.                         break;
  283.                         
  284.                     case 7:
  285.                          $ret .= $this->_sep . 'diciassette';
  286.                         break;
  287.                         
  288.                     case 8:
  289.                         $ret .= $this->_sep . 'diciotto';
  290.                         break;
  291.                         
  292.                     case 9:
  293.                      $ret .= $this->_sep . 'diciannove';
  294.                         break;
  295.                     }
  296.             break;
  297.         }
  298.  
  299.         // add digits only if it is a multiple of 10 and not 1x or 2x
  300.         if (($t != 1) and ($t != 2) and ($d > 0))
  301.         {
  302.             if($t != 0) // don't add 'e' for numbers below 10
  303.             {
  304.                 // use 'un' instead of 'uno' when there is a suffix ('mila', 'milloni', etc...)
  305.                 if(($power > 0) and ($d == 1)) {
  306.                     $ret .= $this->_sep.' e un';
  307.                 }
  308.                 else {
  309.                     $ret .= $this->_sep.''.$this->_digits[$d];
  310.                 }
  311.             }
  312.             else {
  313.                 if(($power > 0) and ($d == 1)) {
  314.                     $ret .= $this->_sep.'un ';
  315.                 }
  316.                 else {
  317.                     $ret .= $this->_sep.$this->_digits[$d];
  318.                 }
  319.             }
  320.         }
  321.  
  322.         if ($power > 0)
  323.         {
  324.             if (isset($this->_exponent[$power])) {
  325.                 $lev = $this->_exponent[$power];
  326.             }
  327.  
  328.             if (!isset($lev) || !is_array($lev)) {
  329.                 return null;
  330.             }
  331.  
  332.             // if it's only one use the singular suffix
  333.             if (($d == 1) and ($t == 0) and ($h == 0)) {
  334.                 $suffix = $lev[0];
  335.             }
  336.             else {
  337.                 $suffix = $lev[1];
  338.             }
  339.             if ($num != 0)  {
  340.                 $ret .= $this->_sep . $suffix;
  341.             }
  342.         }
  343.  
  344.         return $ret;
  345.     }
  346.     // }}}
  347. }
  348. ?>
  349.