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.lt.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  8.1 KB  |  311 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: Laurynas Butkus                                             |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: lang.lt.php,v 1.1 2004/09/02 11:07:59 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Lithuanian language.
  23. //
  24.  
  25. /**
  26.  * Class for translating numbers into Lithuanian.
  27.  *
  28.  * @author Laurynas Butkus
  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 Lithuanian.
  39.  *
  40.  * @author Laurynas Butkus
  41.  * @package Numbers_Words
  42.  */
  43. class Numbers_Words_lt extends Numbers_Words
  44. {
  45.  
  46.     // {{{ properties
  47.     
  48.     /**
  49.      * Locale name
  50.      * @var string
  51.      * @access public
  52.      */
  53.     var $locale      = 'lt';
  54.  
  55.     /**
  56.      * Language name in English
  57.      * @var string
  58.      * @access public
  59.      */
  60.     var $lang        = 'Lithuanian';
  61.  
  62.     /**
  63.      * Native language name
  64.      * @var string
  65.      * @access public
  66.      */
  67.     var $lang_native = 'lietuvi≡kai';
  68.     
  69.     /**
  70.      * The word for the minus sign
  71.      * @var string
  72.      * @access private
  73.      */
  74.     var $_minus = 'minus'; // minus sign
  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('t√kstantis','t√kstanΦiai','t√kstanΦi°'),
  84.         6 => array('milijonas','milijonai','milijon°'),
  85.         9 => array('bilijonas','bilijonai','bilijon°'),
  86.        12 => array('trilijonas','trilijonai','trilijon°'),
  87.        15 => array('kvadrilijonas','kvadrilijonai','kvadrilijon°'),
  88.        18 => array('kvintilijonas','kvintilijonai','kvintilijon°')
  89.         );
  90.  
  91.     /**
  92.      * The array containing the digits (indexed by the digits themselves).
  93.      * @var array
  94.      * @access private
  95.      */
  96.     var $_digits = array(
  97.         0 => 'nulis', 'vienas', 'du', 'trys', 'keturi',
  98.         'penki', '≡e≡i', 'septyni', 'a≡tuoni', 'devyni'
  99.     );
  100.  
  101.     /**
  102.      * The word separator
  103.      * @var string
  104.      * @access private
  105.      */
  106.     var $_sep = ' ';
  107.  
  108.     /**
  109.      * The default currency name
  110.      * @var string
  111.      * @access public
  112.      */
  113.     var $def_currency = 'LTL';
  114.  
  115.     // }}}
  116.     // {{{ toWords()
  117.  
  118.     /**
  119.      * Converts a number to its word representation
  120.      * in Lithuanian language
  121.      *
  122.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  123.      *                        that need to be converted to words
  124.      * @param  integer $power The power of ten for the rest of the number to the right.
  125.      *                        Optional, defaults to 0.
  126.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  127.      *                        Used internally. Optional, defaults to ''.
  128.      *
  129.      * @return string  The corresponding word representation
  130.      *
  131.      * @access public
  132.      * @author Laurynas Butkus <lauris@night.lt>
  133.      * @since  PHP 4.2.3
  134.      */
  135.     function toWords($num, $power = 0, $powsuffix = '') {
  136.       $ret = '';        
  137.       
  138.       // add a minus sign
  139.       if (substr($num, 0, 1) == '-') {
  140.         $ret = $this->_sep . $this->_minus;
  141.         $num = substr($num, 1);
  142.       }
  143.         
  144.       // strip excessive zero signs and spaces
  145.       $num = trim($num);
  146.       $num = preg_replace('/^0+/','',$num);
  147.         
  148.       if (strlen($num) > 3) {
  149.           $maxp = strlen($num)-1;
  150.           $curp = $maxp;
  151.           for ($p = $maxp; $p > 0; --$p) { // power
  152.             
  153.             // check for highest power
  154.             if (isset($this->_exponent[$p])) {
  155.               // send substr from $curp to $p
  156.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  157.               $snum = preg_replace('/^0+/','',$snum);
  158.               if ($snum !== '') {
  159.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  160.                   if ($powsuffix != '')
  161.                     $cursuffix .= $this->_sep . $powsuffix;
  162.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  163.               }
  164.               $curp = $p - 1;
  165.               continue;
  166.             }
  167.           }
  168.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  169.           if ($num == 0) {
  170.               return $ret;
  171.           }
  172.       } elseif ($num == 0 || $num == '') {
  173.         return $this->_sep . $this->_digits[0];
  174.       }
  175.     
  176.       $h = $t = $d = 0;
  177.             
  178.       switch(strlen($num)) {
  179.         case 3:
  180.           $h = (int)substr($num,-3,1);
  181.  
  182.         case 2:
  183.           $t = (int)substr($num,-2,1);
  184.  
  185.         case 1:
  186.           $d = (int)substr($num,-1,1);
  187.           break;
  188.  
  189.         case 0:
  190.           return;
  191.           break;
  192.       }
  193.           
  194.       if ( $h > 1 )
  195.         $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . '≡imtai';
  196.       elseif ( $h )
  197.         $ret .= $this->_sep . '≡imtas';
  198.  
  199.       // ten, twenty etc.
  200.       switch ($t) {
  201.       case 9:
  202.           $ret .= $this->_sep . 'devyniasde≡imt';
  203.           break;
  204.  
  205.       case 8:
  206.           $ret .= $this->_sep . 'a≡tuoniasde≡imt';
  207.           break;
  208.  
  209.       case 7:
  210.           $ret .= $this->_sep . 'septyniasde≡imt';
  211.           break;
  212.  
  213.       case 6:
  214.           $ret .= $this->_sep . '≡e≡iasde≡imt';
  215.           break;
  216.         
  217.       case 5:
  218.           $ret .= $this->_sep . 'penkiasde≡imt';
  219.           break;
  220.     
  221.       case 4:
  222.           $ret .= $this->_sep . 'keturiasde≡imt';
  223.           break;
  224.     
  225.       case 3:
  226.           $ret .= $this->_sep . 'trisde≡imt';
  227.           break;
  228.     
  229.       case 2:
  230.           $ret .= $this->_sep . 'dvide≡imt';
  231.           break;
  232.     
  233.       case 1:
  234.           switch ($d) {
  235.           case 0:
  236.               $ret .= $this->_sep . 'de≡imt';
  237.               break;
  238.     
  239.           case 1:
  240.               $ret .= $this->_sep . 'vienuolika';
  241.               break;
  242.     
  243.           case 2:
  244.               $ret .= $this->_sep . 'dvylika';
  245.               break;
  246.     
  247.           case 3:
  248.               $ret .= $this->_sep . 'trylika';
  249.               break;    
  250.  
  251.           case 4:
  252.               $ret .= $this->_sep . 'keturiolika';
  253.               break;    
  254.     
  255.           case 5:
  256.               $ret .= $this->_sep . 'penkiolika';
  257.               break;
  258.  
  259.           case 6:
  260.               $ret .= $this->_sep . '≡e≡iolika';
  261.               break;
  262.  
  263.           case 7:
  264.               $ret .= $this->_sep . 'septyniolika';
  265.               break;
  266.     
  267.           case 8:
  268.               $ret .= $this->_sep . 'a≡tuoniolika';
  269.               break;
  270.  
  271.           case 9:
  272.               $ret .= $this->_sep . 'devyniolika';
  273.               break;
  274.  
  275.           }
  276.           break; 
  277.       }
  278.  
  279.       if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
  280.           if ( $d > 1 || !$power || $t )
  281.           $ret .= $this->_sep . $this->_digits[$d];
  282.       }
  283.   
  284.       if ($power > 0) {
  285.         if (isset($this->_exponent[$power]))
  286.           $lev = $this->_exponent[$power];
  287.     
  288.         if (!isset($lev) || !is_array($lev))
  289.           return null;
  290.  
  291.         //echo " $t $d  <br>";
  292.         
  293.         if ( $t == 1 || ( $t > 0 && $d == 0 ) )
  294.             $ret .= $this->_sep . $lev[2];
  295.         elseif ( $d > 1 )
  296.             $ret .= $this->_sep . $lev[1];        
  297.         else
  298.             $ret .= $this->_sep . $lev[0];        
  299.       }
  300.     
  301.       if ($powsuffix != '')
  302.         $ret .= $this->_sep . $powsuffix;
  303.     
  304.       return $ret;
  305.     }
  306.     // }}}
  307.  
  308. }
  309.  
  310. ?>
  311.