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.pl.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  17.8 KB  |  521 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.pl.php,v 1.4 2005/09/18 19:52:22 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Polish.
  23. //
  24.  
  25. /**
  26.  * Class for translating numbers into Polish.
  27.  *
  28.  * @author Piotr Klaban
  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 Polish.
  39.  *
  40.  * @author Piotr Klaban
  41.  * @package Numbers_Words
  42.  */
  43. class Numbers_Words_pl extends Numbers_Words
  44. {
  45.  
  46.     // {{{ properties
  47.     
  48.     /**
  49.      * Locale name
  50.      * @var string
  51.      * @access public
  52.      */
  53.     var $locale      = 'pl';
  54.  
  55.     /**
  56.      * Language name in English
  57.      * @var string
  58.      * @access public
  59.      */
  60.     var $lang        = 'Polish';
  61.  
  62.     /**
  63.      * Native language name
  64.      * @var string
  65.      * @access public
  66.      */
  67.     var $lang_native = 'polski';
  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.      * Names based on:
  79.      * mathematical tables, my memory, and also:
  80.      * http://ux1.math.us.edu.pl/~szyjewski/FAQ/liczby/iony.htm
  81.      * @var array
  82.      * @access private
  83.      */
  84.     var $_exponent = array(
  85.        // potΩga dziesi▒tki => liczba pojedyncza, podw≤jna, mnoga
  86.         0 => array('','',''),
  87.         3 => array('tysi▒c','tysi▒ce','tysiΩcy'),
  88.         6 => array('milion','miliony','milion≤w'),
  89.         9 => array('miliard','miliardy','miliard≤w'),
  90.        12 => array('bilion','biliony','bilion≤w'),
  91.        15 => array('biliard','biliardy','biliard≤w'),
  92.        18 => array('trylion','tryliony','trylion≤w'),
  93.        21 => array('tryliard','tryliardy','tryliard≤w'),
  94.        24 => array('kwadrylion','kwadryliony','kwadrylion≤w'),
  95.        27 => array('kwadryliard','kwadryliardy','kwadryliard≤w'),
  96.        30 => array('kwintylion','kwintyliony','kwintylion≤w'),
  97.        33 => array('kwintyliiard','kwintyliardy','kwintyliard≤w'),
  98.        36 => array('sekstylion','sekstyliony','sekstylion≤w'),
  99.        39 => array('sekstyliard','sekstyliardy','sekstyliard≤w'),
  100.        42 => array('septylion','septyliony','septylion≤w'),
  101.        45 => array('septyliard','septyliardy','septyliard≤w'),
  102.        48 => array('oktylion','oktyliony','oktylion≤w'),
  103.        51 => array('oktyliard','oktyliardy','oktyliard≤w'),
  104.        54 => array('nonylion','nonyliony','nonylion≤w'),
  105.        57 => array('nonyliard','nonyliardy','nonyliard≤w'),
  106.        60 => array('decylion','decyliony','decylion≤w'),
  107.        63 => array('decyliard','decyliardy','decyliard≤w'),
  108.       100 => array('centylion','centyliony','centylion≤w'),
  109.       103 => array('centyliard','centyliardy','centyliard≤w'),
  110.       120 => array('wicylion','wicylion','wicylion'),
  111.       123 => array('wicyliard','wicyliardy','wicyliard≤w'),
  112.       180 => array('trycylion','trycylion','trycylion'),
  113.       183 => array('trycyliard','trycyliardy','trycyliard≤w'),
  114.       240 => array('kwadragilion','kwadragilion','kwadragilion'),
  115.       243 => array('kwadragiliard','kwadragiliardy','kwadragiliard≤w'),
  116.       300 => array('kwinkwagilion','kwinkwagilion','kwinkwagilion'),
  117.       303 => array('kwinkwagiliard','kwinkwagiliardy','kwinkwagiliard≤w'),
  118.       360 => array('seskwilion','seskwilion','seskwilion'),
  119.       363 => array('seskwiliard','seskwiliardy','seskwiliard≤w'),
  120.       420 => array('septagilion','septagilion','septagilion'),
  121.       423 => array('septagiliard','septagiliardy','septagiliard≤w'),
  122.       480 => array('oktogilion','oktogilion','oktogilion'),
  123.       483 => array('oktogiliard','oktogiliardy','oktogiliard≤w'),
  124.       540 => array('nonagilion','nonagilion','nonagilion'),
  125.       543 => array('nonagiliard','nonagiliardy','nonagiliard≤w'),
  126.       600 => array('centylion','centyliony','centylion≤w'),
  127.       603 => array('centyliard','centyliardy','centyliard≤w'),
  128.   6000018 => array('milinilitrylion','milinilitryliony','milinilitrylion≤w')
  129.         );
  130.  
  131.     /**
  132.      * The array containing the digits (indexed by the digits themselves).
  133.      * @var array
  134.      * @access private
  135.      */
  136.     var $_digits = array(
  137.         0 => 'zero', 'jeden', 'dwa', 'trzy', 'cztery',
  138.         'piΩµ', 'sze╢µ', 'siedem', 'osiem', 'dziewiΩµ'
  139.     );
  140.  
  141.     /**
  142.      * The word separator
  143.      * @var string
  144.      * @access private
  145.      */
  146.     var $_sep = ' ';
  147.  
  148.     /**
  149.      * The currency names (based on the below links,
  150.      * informations from central bank websites and on encyclopedias)
  151.      *
  152.      * @var array
  153.      * @link http://www.xe.com/iso4217.htm Currency codes
  154.      * @link http://www.republika.pl/geographia/peuropy.htm Europe review
  155.      * @link http://pieniadz.hoga.pl/waluty_objasnienia.asp Currency service
  156.      * @access private
  157.      */
  158.     var $_currency_names = array(
  159.       'ALL' => array(array('lek','leki','lek≤w'), array('quindarka','quindarki','quindarek')),
  160.       'AUD' => array(array('dolar australijski', 'dolary australijskie', 'dolar≤w australijskich'), array('cent', 'centy', 'cent≤w')),
  161.       'BAM' => array(array('marka','marki','marek'), array('fenig','fenigi','fenig≤w')),
  162.       'BGN' => array(array('lew','lewy','lew'), array('stotinka','stotinki','stotinek')),
  163.       'BRL' => array(array('real','reale','real≤w'), array('centavos','centavos','centavos')),
  164.       'BYR' => array(array('rubel','ruble','rubli'), array('kopiejka','kopiejki','kopiejek')),
  165.       'CAD' => array(array('dolar kanadyjski', 'dolary kanadyjskie', 'dolar≤w kanadyjskich'), array('cent', 'centy', 'cent≤w')),
  166.       'CHF' => array(array('frank szwajcarski','franki szwajcarskie','frank≤w szwajcarskich'), array('rapp','rappy','rapp≤w')),
  167.       'CYP' => array(array('funt cypryjski','funty cypryjskie','funt≤w cypryjskich'), array('cent', 'centy', 'cent≤w')),
  168.       'CZK' => array(array('korona czeska','korony czeskie','koron czeskich'), array('halerz','halerze','halerzy')),
  169.       'DKK' => array(array('korona du±ska','korony du±skie','koron du±skich'), array('ore','ore','ore')),
  170.       'EEK' => array(array('korona esto±ska','korony esto±skie','koron esto±skich'), array('senti','senti','senti')),
  171.       'EUR' => array(array('euro', 'euro', 'euro'), array('eurocent', 'eurocenty', 'eurocent≤w')),
  172.       'GBP' => array(array('funt szterling','funty szterlingi','funt≤w szterling≤w'), array('pens','pensy','pens≤w')),
  173.       'HKD' => array(array('dolar Hongkongu','dolary Hongkongu','dolar≤w Hongkongu'), array('cent', 'centy', 'cent≤w')),
  174.       'HRK' => array(array('kuna','kuny','kun'), array('lipa','lipy','lip')),
  175.       'HUF' => array(array('forint','forinty','forint≤w'), array('filler','fillery','filler≤w')),
  176.       'ILS' => array(array('nowy szekel','nowe szekele','nowych szekeli'), array('agora','agory','agorot')),
  177.       'ISK' => array(array('korona islandzka','korony islandzkie','koron islandzkich'), array('aurar','aurar','aurar')),
  178.       'JPY' => array(array('jen','jeny','jen≤w'), array('sen','seny','sen≤w')),
  179.       'LTL' => array(array('lit','lity','lit≤w'), array('cent', 'centy', 'cent≤w')),
  180.       'LVL' => array(array('│at','│aty','│at≤w'), array('sentim','sentimy','sentim≤w')),
  181.       'MKD' => array(array('denar','denary','denar≤w'), array('deni','deni','deni')),
  182.       'MTL' => array(array('lira malta±ska','liry malta±skie','lir malta±skich'), array('centym','centymy','centym≤w')),
  183.       'NOK' => array(array('korona norweska','korony norweskie','koron norweskich'), array('oere','oere','oere')),
  184.       'PLN' => array(array('z│oty', 'z│ote', 'z│otych'), array('grosz', 'grosze', 'groszy')),
  185.       'ROL' => array(array('lej','leje','lei'), array('bani','bani','bani')),
  186.       'RUB' => array(array('rubel','ruble','rubli'), array('kopiejka','kopiejki','kopiejek')),
  187.       'SEK' => array(array('korona szwedzka','korony szwedzkie','koron szweckich'), array('oere','oere','oere')),
  188.       'SIT' => array(array('tolar','tolary','tolar≤w'), array('stotinia','stotinie','stotini')),
  189.       'SKK' => array(array('korona s│owacka','korony s│owackie','koron s│owackich'), array('halerz','halerze','halerzy')),
  190.       'TRL' => array(array('lira turecka','liry tureckie','lir tureckich'), array('kurusza','kurysze','kuruszy')),
  191.       'UAH' => array(array('hrywna','hrywna','hrywna'), array('cent', 'centy', 'cent≤w')),
  192.       'USD' => array(array('dolar','dolary','dolar≤w'), array('cent', 'centy', 'cent≤w')),
  193.       'YUM' => array(array('dinar','dinary','dinar≤w'), array('para','para','para')),
  194.       'ZAR' => array(array('rand','randy','rand≤w'), array('cent', 'centy', 'cent≤w'))
  195.     );
  196.  
  197.     /**
  198.      * The default currency name
  199.      * @var string
  200.      * @access public
  201.      */
  202.     var $def_currency = 'PLN'; // Polish zloty
  203.  
  204.     // }}}
  205.     // {{{ toWords()
  206.  
  207.     /**
  208.      * Converts a number to its word representation
  209.      * in Polish language
  210.      *
  211.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  212.      *                        that need to be converted to words
  213.      * @param  integer $power The power of ten for the rest of the number to the right.
  214.      *                        Optional, defaults to 0.
  215.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  216.      *                        Used internally. Optional, defaults to ''.
  217.      *
  218.      * @return string  The corresponding word representation
  219.      *
  220.      * @access public
  221.      * @author Piotr Klaban <makler@man.torun.pl>
  222.      * @since  PHP 4.2.3
  223.      */
  224.     function toWords($num, $power = 0, $powsuffix = '') {
  225.       $ret = '';        
  226.  
  227.       // add a minus sign
  228.       if (substr($num, 0, 1) == '-') {
  229.         $ret = $this->_sep . $this->_minus;
  230.         $num = substr($num, 1);
  231.       }
  232.         
  233.       // strip excessive zero signs and spaces
  234.       $num = trim($num);
  235.       $num = preg_replace('/^0+/','',$num);
  236.         
  237.       if (strlen($num) > 3) {
  238.           $maxp = strlen($num)-1;
  239.           $curp = $maxp;
  240.           for ($p = $maxp; $p > 0; --$p) { // power
  241.             
  242.             // check for highest power
  243.             if (isset($this->_exponent[$p])) {
  244.               // send substr from $curp to $p
  245.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  246.               $snum = preg_replace('/^0+/','',$snum);
  247.               if ($snum !== '') {
  248.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  249.                   if ($powsuffix != '')
  250.                     $cursuffix .= $this->_sep . $powsuffix;
  251.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  252.               }
  253.               $curp = $p - 1;
  254.               continue;
  255.             }
  256.           }
  257.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  258.           if ($num == 0) {
  259.               return $ret;
  260.           }
  261.       } elseif ($num == 0 || $num == '') {
  262.         return $this->_sep . $this->_digits[0];
  263.       }
  264.     
  265.       $h = $t = $d = 0;
  266.       
  267.       switch(strlen($num)) {
  268.         case 3:
  269.           $h = (int)substr($num,-3,1);
  270.  
  271.         case 2:
  272.           $t = (int)substr($num,-2,1);
  273.  
  274.         case 1:
  275.           $d = (int)substr($num,-1,1);
  276.           break;
  277.  
  278.         case 0:
  279.           return;
  280.           break;
  281.       }
  282.  
  283.       switch ($h) {
  284.       case 9:
  285.           $ret .= $this->_sep . 'dziewiΩµset';
  286.           break;
  287.  
  288.       case 8:
  289.           $ret .= $this->_sep . 'osiemset';
  290.           break;
  291.  
  292.       case 7:
  293.           $ret .= $this->_sep . 'siedemset';
  294.           break;
  295.  
  296.       case 6:
  297.           $ret .= $this->_sep . 'sze╢µset';
  298.           break;
  299.  
  300.       case 5:
  301.           $ret .= $this->_sep . 'piΩµset';
  302.           break;
  303.  
  304.       case 4:
  305.           $ret .= $this->_sep . 'czterysta';
  306.           break;
  307.  
  308.       case 3:
  309.           $ret .= $this->_sep . 'trzysta';
  310.           break;
  311.  
  312.       case 2:
  313.           $ret .= $this->_sep . 'dwie╢cie';
  314.           break;
  315.  
  316.       case 1:
  317.           $ret .= $this->_sep . 'sto';
  318.           break;
  319.       }
  320.  
  321.       switch ($t) {
  322.       case 9:
  323.       case 8:
  324.       case 7:
  325.       case 6:
  326.       case 5:
  327.           $ret .= $this->_sep . $this->_digits[$t] . 'dziesi▒t';
  328.           break;
  329.  
  330.       case 4:
  331.           $ret .= $this->_sep . 'czterdzie╢ci';
  332.           break;
  333.  
  334.       case 3:
  335.           $ret .= $this->_sep . 'trzydzie╢ci';
  336.           break;
  337.  
  338.       case 2:
  339.           $ret .= $this->_sep . 'dwadzie╢cia';
  340.           break;
  341.  
  342.       case 1:
  343.           switch ($d) {
  344.           case 0:
  345.               $ret .= $this->_sep . 'dziesiΩµ';
  346.               break;
  347.  
  348.           case 1:
  349.               $ret .= $this->_sep . 'jedena╢cie';
  350.               break;
  351.  
  352.           case 2:
  353.           case 3:
  354.           case 7:
  355.           case 8:
  356.               $ret .= $this->_sep . $this->_digits[$d] . 'na╢cie';
  357.               break;
  358.  
  359.           case 4:
  360.               $ret .= $this->_sep . 'czterna╢cie';
  361.               break;
  362.  
  363.           case 5:
  364.               $ret .= $this->_sep . 'piΩtna╢cie';
  365.               break;
  366.  
  367.           case 6:
  368.               $ret .= $this->_sep . 'szesna╢cie';
  369.               break;
  370.  
  371.           case 9:
  372.               $ret .= $this->_sep . 'dziewiΩtna╢cie';
  373.               break;
  374.           }
  375.           break; 
  376.       }
  377.  
  378.       if ($t != 1 && $d > 0)
  379.         $ret .= $this->_sep . $this->_digits[$d];
  380.   
  381.       if ($t == 1)
  382.         $d = 0;
  383.  
  384.       if (( $h + $t ) > 0 && $d == 1)
  385.         $d = 0;
  386.  
  387.       if ($power > 0) {
  388.         if (isset($this->_exponent[$power]))
  389.           $lev = $this->_exponent[$power];
  390.  
  391.         if (!isset($lev) || !is_array($lev))
  392.           return null;
  393.  
  394.         switch ($d) {
  395.           case 1:
  396.             $suf = $lev[0];
  397.             break;
  398.           case 2:
  399.           case 3:
  400.           case 4:
  401.             $suf = $lev[1];
  402.             break;
  403.           case 0:
  404.           case 5:
  405.           case 6:
  406.           case 7:
  407.           case 8:
  408.           case 9:
  409.             $suf = $lev[2];
  410.             break;
  411.         }
  412.         $ret .= $this->_sep . $suf;
  413.       }
  414.   
  415.       if ($powsuffix != '')
  416.         $ret .= $this->_sep . $powsuffix;
  417.  
  418.       return $ret;
  419.     }
  420.     // }}}
  421.     // {{{ toCurrencyWords()
  422.  
  423.     /**
  424.      * Converts a currency value to its word representation
  425.      * (with monetary units) in Polish language
  426.      *
  427.      * @param  integer $int_curr An international currency symbol
  428.      *                 as defined by the ISO 4217 standard (three characters)
  429.      * @param  integer $decimal A money total amount without fraction part (e.g. amount of dollars)
  430.      * @param  integer $fraction Fractional part of the money amount (e.g. amount of cents)
  431.      *                 Optional. Defaults to false.
  432.      * @param  integer $convert_fraction Convert fraction to words (left as numeric if set to false).
  433.      *                 Optional. Defaults to true.
  434.      *
  435.      * @return string  The corresponding word representation for the currency
  436.      *
  437.      * @access public
  438.      * @author Piotr Klaban <makler@man.torun.pl>
  439.      * @since  Numbers_Words 0.4
  440.      */
  441.     function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) {
  442.         $int_curr = strtoupper($int_curr);
  443.         if (!isset($this->_currency_names[$int_curr])) {
  444.             $int_curr = $this->def_currency;
  445.         }
  446.         $curr_names = $this->_currency_names[$int_curr];
  447.         $ret  = trim($this->toWords($decimal));
  448.         $lev  = $this->_get_numlevel($decimal);
  449.         $ret .= $this->_sep . $curr_names[0][$lev];
  450.       
  451.         if ($fraction !== false) {
  452.             if ($convert_fraction) {
  453.                 $ret .= $this->_sep . trim($this->toWords($fraction));
  454.             } else {
  455.                 $ret .= $this->_sep . $fraction;
  456.             }
  457.             $lev  = $this->_get_numlevel($fraction);    
  458.             $ret .= $this->_sep . $curr_names[1][$lev];
  459.         }
  460.         return $ret;
  461.     }
  462.     // }}}
  463.     // {{{ _get_numlevel()
  464.     
  465.     /**
  466.      * Returns grammatical "level" of the number - this is necessary
  467.      * for choosing the right suffix for exponents and currency names.
  468.      *
  469.      * @param  integer $num   An integer between -infinity and infinity inclusive
  470.      *                        that need to be converted to words
  471.      *
  472.      * @return integer  The grammatical "level" of the number.
  473.      *
  474.      * @access private
  475.      * @author Piotr Klaban <makler@man.torun.pl>
  476.      * @since  Numbers_Words 0.4
  477.      */
  478.     function _get_numlevel($num) {
  479.         $num = (int)substr($num,-3);
  480.         $h = $t = $d = $lev = 0;
  481.         
  482.         switch(strlen($num)) {
  483.             case 3:
  484.                 $h = (int)substr($num,-3,1);
  485.  
  486.             case 2:
  487.                 $t = (int)substr($num,-2,1);
  488.  
  489.             case 1:
  490.                 $d = (int)substr($num,-1,1);
  491.                 break;
  492.  
  493.             case 0:
  494.                 return $lev;
  495.                 break;
  496.         }
  497.         if ($t == 1)
  498.             $d = 0;
  499.  
  500.         if (( $h + $t ) > 0 && $d == 1)
  501.             $d = 0;
  502.  
  503.         switch ($d) {
  504.             case 1:
  505.                 $lev = 0;
  506.                 break;
  507.             case 2:
  508.             case 3:
  509.             case 4:
  510.                 $lev = 1;
  511.                 break;
  512.             default:
  513.                 $lev = 2;
  514.         }
  515.         return $lev;
  516.     }
  517.     // }}}
  518. }
  519.  
  520. ?>
  521.