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.cs.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  9.9 KB  |  340 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: Petr 'PePa' Pavel <petr.pavel@pepa.info>                    |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: lang.cs.php,v 1.1 2005/02/28 13:22:51 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Czech language.
  23. //
  24.  
  25. /**
  26.  * Class for translating numbers into Czech.
  27.  *
  28.  * @author Petr 'PePa' Pavel
  29.  * @package Numbers_Words
  30.  */
  31.  
  32. /**
  33.  * Include needed files
  34.  */
  35. require_once("Numbers/Words.php");
  36.  
  37. /**
  38.  * Class for translating numbers into Czech.
  39.  *
  40.  * @author Petr 'PePa' Pavel
  41.  * @package Numbers_Words
  42.  */
  43. class Numbers_Words_cs extends Numbers_Words
  44. {
  45.  
  46.     // {{{ properties
  47.     
  48.     /**
  49.      * Locale name
  50.      * @var string
  51.      * @access public
  52.      */
  53.     var $locale      = 'cs';
  54.  
  55.     /**
  56.      * Language name in English
  57.      * @var string
  58.      * @access public
  59.      */
  60.     var $lang        = 'Czech';
  61.  
  62.     /**
  63.      * Native language name
  64.      * @var string
  65.      * @access public
  66.      */
  67.     var $lang_native = 'Czech';
  68.     
  69.     /**
  70.      * The word for the minus sign
  71.      * @var string
  72.      * @access private
  73.      */
  74.     var $_minus = 'mφnus'; // minus sign
  75.  
  76.     /**
  77.      * The sufixes for exponents (singular and plural)
  78.      * Names partly based on:
  79.      * http://cs.wikipedia.org/wiki/P%C5%99edpony_soustavy_SI
  80.      * the rest was translated from lang.en_GB.php
  81.      * names verified by "Ustav pro jazyk cesky" only up to Septilion
  82.      * (they could verify only the lingual matter - not the mathematical one)
  83.      * @var array
  84.      * @access private
  85.      */
  86.  
  87.     var $_exponent = array(
  88.         0 => array(''),
  89.         3 => array('tisφc','tisφce','tisφc'),
  90.         6 => array('milion','miliony','milion∙'),
  91.         9 => array('miliarda','miliardy','miliard'),
  92.        12 => array('bilion','biliony','bilion∙'),
  93.        15 => array('biliarda','biliardy','biliard'),
  94.        18 => array('trilion','triliony','trilion∙'),
  95.        21 => array('triliarda','triliardy','triliard'),
  96.  
  97.        24 => array('kvadrilion','kvadriliony','kvadrilion∙'),
  98.        30 => array('kvintilion','kvintiliony','kvintilion∙'),
  99.        36 => array('sextilion','sextiliony','sextilion∙'),
  100.        42 => array('septilion','septiliony','septilion∙'),
  101.  
  102.        48 => array('oktilion','oktiliony','oktilion∙'),
  103.        54 => array('nonilion','noniliony','nonilion∙'),
  104.        60 => array('decilion','deciliony','decilion∙'),
  105.  
  106.        66 => array('undecilion','undeciliony','undecilion∙'),
  107.        72 => array('duodecilion','duodeciliony','duodecilion∙'),
  108.        78 => array('tredecilion','tredeciliony','tredecilion∙'),
  109.        84 => array('kvatrodecilion','kvatrodeciliony','kvatrodecilion∙'),
  110.        90 => array('kvindecilion','kvindeciliony','kvindecilion∙'),
  111.        96 => array('sexdecilion','sexdeciliony','sexdecilion∙'),
  112.       102 => array('septendecilion','septendeciliony','septendecilion∙'),
  113.       108 => array('oktodecilion','oktodeciliony','oktodecilion∙'),
  114.       114 => array('novemdecilion','novemdeciliony','novemdecilion∙'),
  115.       120 => array('vigintilion','vigintiliony','vigintilion∙'),
  116.       192 => array('duotrigintilion','duotrigintiliony','duotrigintilion∙'),
  117.       600 => array('centilion','centiliony','centilion∙')
  118.  
  119.         );
  120.  
  121.     /**
  122.      * The array containing the forms of Czech word for "hundred"
  123.      * @var array
  124.      * @access private
  125.      */
  126.     var $_hundreds = array(
  127.         0 => 'sto', 'st∞', 'sta', 'set'
  128.     );
  129.  
  130.     /**
  131.      * The array containing the digits (indexed by the digits themselves).
  132.      * @var array
  133.      * @access private
  134.      */
  135.     var $_digits = array(
  136.         0 => 'nula', 'jedna', 'dva', 't°i', 'Φty°i',
  137.         'p∞t', '╣est', 'sedm', 'osm', 'dev∞t'
  138.     );
  139.  
  140.     /**
  141.      * The word separator
  142.      * @var string
  143.      * @access private
  144.      */
  145.     var $_sep = ' ';
  146.  
  147.     // }}}
  148.     // {{{ toWords()
  149.  
  150.     /**
  151.      * Converts a number to its word representation
  152.      * in Czech language
  153.      *
  154.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  155.      *                        that need to be converted to words
  156.      * @param  integer $power The power of ten for the rest of the number to the right.
  157.      *                        Optional, defaults to 0.
  158.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  159.      *                        Used internally. Optional, defaults to ''.
  160.      *
  161.      * @return string  The corresponding word representation
  162.      *
  163.      * @access public
  164.      * @author Petr 'PePa' Pavel <petr.pavel@pepa.info>
  165.      * @since  PHP 4.2.3
  166.      */
  167.     function toWords($num, $power = 0, $powsuffix = '') {
  168. //    print "<br>$num,$power,$powsuffix<br>";
  169.       $ret = '';        
  170.         
  171.       // add a minus sign
  172.       if (substr($num, 0, 1) == '-') {
  173.         $ret = $this->_sep . $this->_minus;
  174.         $num = substr($num, 1);
  175.       }
  176.         
  177.       // strip excessive zero signs and spaces
  178.       $num = trim($num);
  179.       $num = preg_replace('/^0+/','',$num);
  180.         
  181.       if (strlen($num) > 3) {
  182.           $maxp = strlen($num)-1;
  183.           $curp = $maxp;
  184.           for ($p = $maxp; $p > 0; --$p) { // power
  185.             
  186.             // check for highest power
  187.             if (isset($this->_exponent[$p])) {
  188.               // send substr from $curp to $p
  189.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  190.               $snum = preg_replace('/^0+/','',$snum);
  191.               if ($snum !== '') {
  192.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  193.                   if ($powsuffix != '')
  194.                     $cursuffix .= $this->_sep . $powsuffix;
  195.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  196.               }
  197.               $curp = $p - 1;
  198.               continue;
  199.             }
  200.           }
  201.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  202.           if ($num == 0) {
  203.               return $ret;
  204.           }
  205.       } elseif ($num == 0 || $num == '') {
  206.         return $this->_sep . $this->_digits[0];
  207.       }
  208.     
  209.       $h = $t = $d = 0;
  210.       
  211.       switch(strlen($num)) {
  212.         case 3:
  213.           $h = (int)substr($num,-3,1);
  214.  
  215.         case 2:
  216.           $t = (int)substr($num,-2,1);
  217.  
  218.         case 1:
  219.           $d = (int)substr($num,-1,1);
  220.           break;
  221.  
  222.         case 0:
  223.           return;
  224.           break;
  225.       }
  226.  
  227.       if ($h) {
  228.    
  229.         // inflection of the word "hundred"
  230.         if ($h == 1)
  231.           $ret .= $this->_sep . $this->_hundreds[0];
  232.         elseif ($h == 2)
  233.           $ret .= $this->_sep . "dv∞" . $this->_sep . $this->_hundreds[1];
  234.         elseif ( ($h > 1) && ($h < 5) )
  235.           $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . $this->_hundreds[2];
  236.         else        //if ($h >= 5)
  237.           $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . $this->_hundreds[3];
  238.  
  239.         // in English only - add ' and' for [1-9]01..[1-9]99
  240.         // (also for 1001..1099, 10001..10099 but it is harder)
  241.         // for now it is switched off, maybe some language purists
  242.         // can force me to enable it, or to remove it completely
  243.         // if (($t + $d) > 0)
  244.         //   $ret .= $this->_sep . 'and';
  245.       }
  246.  
  247.       // ten, twenty etc.
  248.       switch ($t) {
  249.       case 2:
  250.       case 3:
  251.       case 4:
  252.           $ret .= $this->_sep . $this->_digits[$t] . 'cet';
  253.           break;
  254.     
  255.       case 5:
  256.           $ret .= $this->_sep . 'padesßt';
  257.           break;
  258.     
  259.       case 6:
  260.           $ret .= $this->_sep . '╣edesßt';
  261.           break;
  262.     
  263.       case 7:
  264.           $ret .= $this->_sep . 'sedmdesßt';
  265.           break;
  266.     
  267.       case 8:
  268.           $ret .= $this->_sep . 'osmdesßt';
  269.           break;
  270.     
  271.       case 9:
  272.           $ret .= $this->_sep . 'devadesßt';
  273.           break;
  274.     
  275.       case 1:
  276.           switch ($d) {
  277.           case 0:
  278.               $ret .= $this->_sep . 'deset';
  279.               break;
  280.     
  281.           case 1:
  282.               $ret .= $this->_sep . 'jedenßct';
  283.               break;
  284.     
  285.           case 4:
  286.               $ret .= $this->_sep . 'Φtrnßct';
  287.               break;
  288.     
  289.           case 5:
  290.               $ret .= $this->_sep . 'patnßct';
  291.               break;
  292.     
  293.           case 9:
  294.               $ret .= $this->_sep . 'devatenßct';
  295.               break;
  296.     
  297.           case 2:
  298.           case 3:
  299.           case 6:
  300.           case 7:
  301.           case 8:
  302.               $ret .= $this->_sep . $this->_digits[$d] . 'nßct';
  303.               break;
  304.           }
  305.           break; 
  306.       }
  307.  
  308.       if ($t != 1 && $d > 0 && ($power == 0 || $d > 1)) {
  309.       // 
  310.         $ret .= $this->_sep . $this->_digits[$d];
  311.       }
  312.   
  313.       if ($power > 0) {
  314.         if (isset($this->_exponent[$power]))
  315.           $lev = $this->_exponent[$power];
  316.     
  317.         if (!isset($lev) || !is_array($lev))
  318.           return null;
  319.  
  320.            // inflection of exponental words
  321.           if ($num == 1)
  322.             $idx = 0;
  323.           elseif ( ($num > 1) && ($num < 5) )
  324.             $idx = 1;
  325.           else        //if ($num >= 5)
  326.             $idx = 2;
  327.  
  328.         $ret .= $this->_sep . $lev[$idx];
  329.       }
  330.     
  331.       if ($powsuffix != '')
  332.         $ret .= $this->_sep . $powsuffix;
  333.     
  334.       return $ret;
  335.     }
  336.     // }}}
  337. }
  338.  
  339. ?>
  340.