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.es_AR.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  15.2 KB  |  475 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: Martin Marrese  <mmare@mecon.gov.ar>                        |
  18. // | Based On: lang_es.php  -  Xavier Noguer                              |
  19. // +----------------------------------------------------------------------+
  20. // $Id: lang.es_AR.php,v 1.3 2005/09/18 19:52:22 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Argentinian Spanish 
  23. // 
  24. //
  25.  
  26. /**
  27.  * Class for translating numbers into Argentinian Spanish.
  28.  *
  29.  * @author Martin Marrese
  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 Argentinian Spanish.
  40.  * It supports up to decallones (10^6).
  41.  * It doesn't support spanish tonic accents (acentos).
  42.  *
  43.  * @author Martin Marrese
  44.  * @package Numbers_Words
  45.  */
  46. class Numbers_Words_es_AR extends Numbers_Words
  47. {
  48.     // {{{ properties
  49.  
  50.     /**
  51.      * Locale name
  52.      * @var string
  53.      * @access public
  54.      */
  55.     var $locale      = 'es_AR';
  56.     
  57.     /**
  58.      * Language name in English
  59.      * @var string
  60.      * @access public
  61.      */
  62.     var $lang        = 'Spanish';
  63.     
  64.     /**
  65.      * Native language name
  66.      * @var string
  67.      * @access public
  68.      */
  69.     var $lang_native = 'Espa±ol';
  70.  
  71.     /**
  72.      * The word for the minus sign
  73.      * @var string
  74.      * @access private
  75.      */
  76.     var $_minus = 'menos';
  77.  
  78.     /**
  79.      * The sufixes for exponents (singular and plural)
  80.      * @var array
  81.      * @access private
  82.      */
  83.     var $_exponent = array(
  84.         0 => array('',''),
  85.         3 => array('mil','mil'),
  86.         6 => array('mill≤n','millones'),
  87.        12 => array('bill≤n','billones'),
  88.        18 => array('tril≤n','trillones'),
  89.        24 => array('cuatrill≤n','cuatrillones'),
  90.        30 => array('quintill≤n','quintillones'),
  91.        36 => array('sextill≤n','sextillones'),
  92.        42 => array('septill≤n','septillones'),
  93.        48 => array('octall≤n','octallones'),
  94.        54 => array('nonall≤n','nonallones'),
  95.        60 => array('decall≤n','decallones'),
  96.         );
  97.     /**
  98.      * The array containing the digits (indexed by the digits themselves).
  99.      * @var array
  100.      * @access private
  101.      */
  102.     var $_digits = array(
  103.         0 => 'cero', 'uno', 'dos', 'tres', 'cuatro',
  104.         'cinco', 'seis', 'siete', 'ocho', 'nueve'
  105.         );
  106.     /**
  107.      * The word separator
  108.      * @var string
  109.      * @access private
  110.      */
  111.     var $_sep = ' ';
  112.     
  113.     /**
  114.      * The currency names (based on the below links,
  115.      * informations from central bank websites and on encyclopedias)
  116.      *
  117.      * @var array
  118.      * @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
  119.      * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
  120.      * @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
  121.      * @access private
  122.      */
  123.     var $_currency_names = array(
  124.       'ALL' => array(array('lek'), array('qindarka')),
  125.       'AUD' => array(array('Australian dollar'), array('cent')),
  126.       'ARS' => array(array('Peso'), array ('centavo')),
  127.       'BAM' => array(array('convertible marka'), array('fenig')),
  128.       'BGN' => array(array('lev'), array('stotinka')),
  129.       'BRL' => array(array('real'), array('centavos')),
  130.       'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
  131.       'CAD' => array(array('Canadian dollar'), array('cent')),
  132.       'CHF' => array(array('Swiss franc'), array('rapp')),
  133.       'CYP' => array(array('Cypriot pound'), array('cent')),
  134.       'CZK' => array(array('Czech koruna'), array('halerz')),
  135.       'DKK' => array(array('Danish krone'), array('ore')),
  136.       'EEK' => array(array('kroon'), array('senti')),
  137.       'EUR' => array(array('euro'), array('euro-cent')),
  138.       'GBP' => array(array('pound', 'pounds'), array('pence')),
  139.       'HKD' => array(array('Hong Kong dollar'), array('cent')),
  140.       'HRK' => array(array('Croatian kuna'), array('lipa')),
  141.       'HUF' => array(array('forint'), array('filler')),
  142.       'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
  143.       'ISK' => array(array('Icelandic kr≤na'), array('aurar')),
  144.       'JPY' => array(array('yen'), array('sen')),
  145.       'LTL' => array(array('litas'), array('cent')),
  146.       'LVL' => array(array('lat'), array('sentim')),
  147.       'MKD' => array(array('Macedonian dinar'), array('deni')),
  148.       'MTL' => array(array('Maltese lira'), array('centym')),
  149.       'NOK' => array(array('Norwegian krone'), array('oere')),
  150.       'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
  151.       'ROL' => array(array('Romanian leu'), array('bani')),
  152.       'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
  153.       'SEK' => array(array('Swedish krona'), array('oere')),
  154.       'SIT' => array(array('Tolar'), array('stotinia')),
  155.       'SKK' => array(array('Slovak koruna'), array()),
  156.       'TRL' => array(array('lira'), array('kuru■')),
  157.       'UAH' => array(array('hryvna'), array('cent')),
  158.       'USD' => array(array('dollar'), array('cent')),
  159.       'YUM' => array(array('dinars'), array('para')),
  160.       'ZAR' => array(array('rand'), array('cent'))
  161.     );
  162.  
  163.     /**
  164.      * The default currency name
  165.      * @var string
  166.      * @access public
  167.      */
  168.     var $def_currency = 'ARS'; // Argentinian Peso
  169.     
  170.     // }}}
  171.     // {{{ toWords()
  172.     /**
  173.      * Converts a number to its word representation
  174.      * in Argentinian Spanish.
  175.      *
  176.      * @param  float $num     An float between -infinity and infinity inclusive :)
  177.      *                        that should be converted to a words representation
  178.      * @param  integer $power The power of ten for the rest of the number to the right.
  179.      *                        For example toWords(12,3) should give "doce mil".
  180.      *                        Optional, defaults to 0.
  181.      * @return string  The corresponding word representation
  182.      *
  183.      * @access private
  184.      * @author Martin Marrese
  185.      */
  186.     function toWords($num, $power = 0)
  187.     {
  188.         // The return string;
  189.         $ret = '';
  190.  
  191.         // add a the word for the minus sign if necessary
  192.         if (substr($num, 0, 1) == '-')
  193.         {
  194.             $ret = $this->_sep . $this->_minus;
  195.             $num = substr($num, 1);
  196.         }
  197.  
  198.  
  199.         // strip excessive zero signs
  200.         $num = preg_replace('/^0+/','',$num);
  201.  
  202.         $num_tmp = split ('\.', $num);
  203.  
  204.         $num = $num_tmp[0];
  205.         $dec = (@$num_tmp[1]) ? $num_tmp[1] : '';
  206.  
  207.         if (strlen($num) > 6)
  208.         {
  209.             $current_power = 6;
  210.             // check for highest power
  211.             if (isset($this->_exponent[$power]))
  212.             {
  213.                 // convert the number above the first 6 digits
  214.                 // with it's corresponding $power.
  215.                 $snum = substr($num, 0, -6);
  216.                 $snum = preg_replace('/^0+/','',$snum);
  217.                 if ($snum !== '') {
  218.                     $ret .= $this->toWords($snum, $power + 6);
  219.                 }
  220.             }
  221.             $num = substr($num, -6);
  222.             if ($num == 0) {
  223.                 return $ret;
  224.             }
  225.         }
  226.         elseif ($num == 0 || $num == '') {
  227.             return(' '.$this->_digits[0]);
  228.             $current_power = strlen($num);
  229.         }
  230.         else {
  231.             $current_power = strlen($num);
  232.         }
  233.  
  234.         // See if we need "thousands"
  235.         $thousands = floor($num / 1000);
  236.         if ($thousands == 1) {
  237.             $ret .= $this->_sep . 'mil';
  238.         }
  239.         elseif ($thousands > 1) {
  240.             $ret .= $this->toWords($thousands, 3);
  241.         }
  242.  
  243.         // values for digits, tens and hundreds
  244.         $h = floor(($num / 100) % 10);
  245.         $t = floor(($num / 10) % 10);
  246.         $d = floor($num % 10);
  247.  
  248.         // cientos: doscientos, trescientos, etc...
  249.         switch ($h)
  250.         {
  251.             case 1:
  252.                 if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
  253.                     $ret .= $this->_sep . 'cien';
  254.                 }
  255.                 else {
  256.                     $ret .= $this->_sep . 'ciento';
  257.                 }
  258.                 break;
  259.             case 2:
  260.             case 3:
  261.             case 4:
  262.             case 6:
  263.             case 8:
  264.                 $ret .= $this->_sep . $this->_digits[$h] . 'cientos';
  265.                 break;
  266.             case 5:
  267.                 $ret .= $this->_sep . 'quinientos';
  268.                 break;
  269.             case 7:
  270.                 $ret .= $this->_sep . 'setecientos';
  271.                 break;
  272.             case 9:
  273.                 $ret .= $this->_sep . 'novecientos';
  274.                 break;
  275.         }
  276.  
  277.         // decenas: veinte, treinta, etc...
  278.         switch ($t)
  279.         {
  280.             case 9:
  281.                 $ret .= $this->_sep . 'noventa';
  282.                 break;
  283.  
  284.             case 8:
  285.                 $ret .= $this->_sep . 'ochenta';
  286.                 break;
  287.  
  288.             case 7:
  289.                 $ret .= $this->_sep . 'setenta';
  290.                 break;
  291.  
  292.             case 6:
  293.                 $ret .= $this->_sep . 'sesenta';
  294.                 break;
  295.  
  296.             case 5:
  297.                 $ret .= $this->_sep . 'cincuenta';
  298.                 break;
  299.  
  300.             case 4:
  301.                 $ret .= $this->_sep . 'cuarenta';
  302.                 break;
  303.  
  304.             case 3:
  305.                 $ret .= $this->_sep . 'treinta';
  306.                 break;
  307.  
  308.             case 2:
  309.                 if ($d == 0) {
  310.                     $ret .= $this->_sep . 'veinte';
  311.                 }
  312.                 else {
  313.                     if (($power > 0) and ($d == 1)) {
  314.                         $ret .= $this->_sep . 'veinti·n';
  315.                     }
  316.                     else {
  317.                         $ret .= $this->_sep . 'veinti' . $this->_digits[$d];
  318.                     }
  319.                 }
  320.                 break;
  321.  
  322.             case 1:
  323.                 switch ($d)
  324.                 {
  325.                     case 0:
  326.                         $ret .= $this->_sep . 'diez';
  327.                         break;
  328.  
  329.                     case 1:
  330.                         $ret .= $this->_sep . 'once';
  331.                         break;
  332.  
  333.                     case 2:
  334.                         $ret .= $this->_sep . 'doce';
  335.                         break;
  336.  
  337.                     case 3:
  338.                         $ret .= $this->_sep . 'trece';
  339.                         break;
  340.  
  341.                     case 4:
  342.                         $ret .= $this->_sep . 'catorce';
  343.                         break;
  344.  
  345.                     case 5:
  346.                         $ret .= $this->_sep . 'quince';
  347.                         break;
  348.  
  349.                     case 6:
  350.                     case 7:
  351.                     case 9:
  352.                     case 8:
  353.                         $ret .= $this->_sep . 'dieci' . $this->_digits[$d];
  354.                         break;
  355.                 }
  356.             break;
  357.         }
  358.  
  359.         // add digits only if it is a multiple of 10 and not 1x or 2x
  360.         if (($t != 1) and ($t != 2) and ($d > 0))
  361.         {
  362.             if($t != 0) // don't add 'y' for numbers below 10
  363.             {
  364.                 // use 'un' instead of 'uno' when there is a suffix ('mil', 'millones', etc...)
  365.                 if(($power > 0) and ($d == 1)) {
  366.                     $ret .= $this->_sep.' y un';
  367.                 }
  368.                 else {
  369.                     $ret .= $this->_sep.'y '.$this->_digits[$d];
  370.                 }
  371.             }
  372.             else {
  373.                 if(($power > 0) and ($d == 1)) {
  374.                     $ret .= $this->_sep.'un';
  375.                 }
  376.                 else {
  377.                     $ret .= $this->_sep.$this->_digits[$d];
  378.                 }
  379.             }
  380.         }
  381.  
  382.         if ($power > 0)
  383.         {
  384.             if (isset($this->_exponent[$power])) {
  385.                 $lev = $this->_exponent[$power];
  386.             }
  387.  
  388.             if (!isset($lev) || !is_array($lev)) {
  389.                 return null;
  390.             }
  391.  
  392.             // if it's only one use the singular suffix
  393.             if (($d == 1) and ($t == 0) and ($h == 0)) {
  394.                 $suffix = $lev[0];
  395.             }
  396.             else {
  397.                 $suffix = $lev[1];
  398.             }
  399.             if ($num != 0)  {
  400.                 $ret .= $this->_sep . $suffix;
  401.             }
  402.         }
  403.  
  404.         if ($dec) {
  405.             $dec = $this->toWords(trim($dec));
  406.             $ret.= ' con ' . trim ($dec);
  407.         }
  408.         
  409.         return $ret;
  410.     }
  411.     // }}}
  412.  
  413.     // {{{ toCurrencyWords()
  414.  
  415.     /**
  416.      * Converts a currency value to its word representation
  417.      * (with monetary units) in Agentinian Spanish language
  418.      *
  419.      * @param  integer $int_curr An international currency symbol
  420.      *                 as defined by the ISO 4217 standard (three characters)
  421.      * @param  integer $decimal A money total amount without fraction part (e.g. amount of dollars)
  422.      * @param  integer $fraction Fractional part of the money amount (e.g. amount of cents)
  423.      *                 Optional. Defaults to false.
  424.      * @param  integer $convert_fraction Convert fraction to words (left as numeric if set to false).
  425.      *                 Optional. Defaults to true.
  426.      *
  427.      * @return string  The corresponding word representation for the currency
  428.      *
  429.      * @access public
  430.      * @author Martin Marrese
  431.      */
  432.     function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) {
  433.         $int_curr = strtoupper($int_curr);
  434.         if (!isset($this->_currency_names[$int_curr])) {
  435.             $int_curr = $this->def_currency;
  436.         }
  437.         $curr_names = $this->_currency_names[$int_curr];
  438.         $lev  = ($decimal == 1) ? 0 : 1;
  439.         if ($lev > 0) {
  440.             if (count($curr_names[0]) > 1) {
  441.                 $ret = $curr_names[0][$lev];
  442.             } else {
  443.                 $ret = $curr_names[0][0] . 's';
  444.             }
  445.         } else {
  446.             $ret = $curr_names[0][0];
  447.         }
  448.         $ret .= $this->_sep . trim($this->toWords($decimal));
  449.       
  450.         if ($fraction !== false) {
  451.             if ($convert_fraction) {
  452.                 $ret .= $this->_sep .'con'. $this->_sep . trim($this->toWords($fraction));
  453.             } else {
  454.                 $ret .= $this->_sep .'con'. $this->_sep . $fraction;
  455.             }
  456.             $lev  = ($fraction == 1) ? 0 : 1;
  457.             if ($lev > 0) {
  458.                 if (count($curr_names[1]) > 1) {
  459.                     $ret .= $this->_sep . $curr_names[1][$lev];
  460.                 } else {
  461.                     $ret .= $this->_sep . $curr_names[1][0] . 's';
  462.                 }
  463.             } else {
  464.                 $ret .= $this->_sep . $curr_names[1][0];
  465.             }
  466.         }
  467.         return $ret;
  468.     }
  469.     // }}}
  470.  
  471.  
  472.     
  473. }
  474. ?>
  475.