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.en_GB.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  13.4 KB  |  425 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.en_GB.php,v 1.4 2005/09/18 19:52:22 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in British English language.
  23. //
  24.  
  25. /**
  26.  * Class for translating numbers into British English.
  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 British English.
  39.  *
  40.  * @author Piotr Klaban
  41.  * @package Numbers_Words
  42.  */
  43. class Numbers_Words_en_GB extends Numbers_Words
  44. {
  45.  
  46.     // {{{ properties
  47.     
  48.     /**
  49.      * Locale name
  50.      * @var string
  51.      * @access public
  52.      */
  53.     var $locale      = 'en_GB';
  54.  
  55.     /**
  56.      * Language name in English
  57.      * @var string
  58.      * @access public
  59.      */
  60.     var $lang        = 'British English';
  61.  
  62.     /**
  63.      * Native language name
  64.      * @var string
  65.      * @access public
  66.      */
  67.     var $lang_native = 'British English';
  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 partly based on:
  79.      * http://www.users.dircon.co.uk/~shaunf/shaun/numbers/millions.htm
  80.      * @var array
  81.      * @access private
  82.      */
  83.     var $_exponent = array(
  84.         0 => array(''),
  85.         3 => array('thousand'),
  86.         6 => array('million'),
  87.        12 => array('billion'),
  88.        18 => array('trillion'),
  89.        24 => array('quadrillion'),
  90.        30 => array('quintillion'),
  91.        36 => array('sextillion'),
  92.        42 => array('septillion'),
  93.        48 => array('octillion'),
  94.        54 => array('nonillion'),
  95.        60 => array('decillion'),
  96.        66 => array('undecillion'),
  97.        72 => array('duodecillion'),
  98.        78 => array('tredecillion'),
  99.        84 => array('quattuordecillion'),
  100.        90 => array('quindecillion'),
  101.        96 => array('sexdecillion'),
  102.       102 => array('septendecillion'),
  103.       108 => array('octodecillion'),
  104.       114 => array('novemdecillion'),
  105.       120 => array('vigintillion'),
  106.       192 => array('duotrigintillion'),
  107.       600 => array('centillion')
  108.         );
  109.  
  110.     /**
  111.      * The array containing the digits (indexed by the digits themselves).
  112.      * @var array
  113.      * @access private
  114.      */
  115.     var $_digits = array(
  116.         0 => 'zero', 'one', 'two', 'three', 'four',
  117.         'five', 'six', 'seven', 'eight', 'nine'
  118.     );
  119.  
  120.     /**
  121.      * The word separator
  122.      * @var string
  123.      * @access private
  124.      */
  125.     var $_sep = ' ';
  126.  
  127.     /**
  128.      * The currency names (based on the below links,
  129.      * informations from central bank websites and on encyclopedias)
  130.      *
  131.      * @var array
  132.      * @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
  133.      * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
  134.      * @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
  135.      * @access private
  136.      */
  137.     var $_currency_names = array(
  138.       'ALL' => array(array('lek'), array('qindarka')),
  139.       'AUD' => array(array('Australian dollar'), array('cent')),
  140.       'BAM' => array(array('convertible marka'), array('fenig')),
  141.       'BGN' => array(array('lev'), array('stotinka')),
  142.       'BRL' => array(array('real'), array('centavos')),
  143.       'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
  144.       'CAD' => array(array('Canadian dollar'), array('cent')),
  145.       'CHF' => array(array('Swiss franc'), array('rapp')),
  146.       'CYP' => array(array('Cypriot pound'), array('cent')),
  147.       'CZK' => array(array('Czech koruna'), array('halerz')),
  148.       'DKK' => array(array('Danish krone'), array('ore')),
  149.       'EEK' => array(array('kroon'), array('senti')),
  150.       'EUR' => array(array('euro'), array('euro-cent')),
  151.       'GBP' => array(array('pound', 'pounds'), array('pence', 'pence')),
  152.       'HKD' => array(array('Hong Kong dollar'), array('cent')),
  153.       'HRK' => array(array('Croatian kuna'), array('lipa')),
  154.       'HUF' => array(array('forint'), array('filler')),
  155.       'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
  156.       'ISK' => array(array('Icelandic kr≤na'), array('aurar')),
  157.       'JPY' => array(array('yen'), array('sen')),
  158.       'LTL' => array(array('litas'), array('cent')),
  159.       'LVL' => array(array('lat'), array('sentim')),
  160.       'MKD' => array(array('Macedonian dinar'), array('deni')),
  161.       'MTL' => array(array('Maltese lira'), array('centym')),
  162.       'NOK' => array(array('Norwegian krone'), array('oere')),
  163.       'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
  164.       'ROL' => array(array('Romanian leu'), array('bani')),
  165.       'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
  166.       'SEK' => array(array('Swedish krona'), array('oere')),
  167.       'SIT' => array(array('Tolar'), array('stotinia')),
  168.       'SKK' => array(array('Slovak koruna'), array()),
  169.       'TRL' => array(array('lira'), array('kuru■')),
  170.       'UAH' => array(array('hryvna'), array('cent')),
  171.       'USD' => array(array('dollar'), array('cent')),
  172.       'YUM' => array(array('dinars'), array('para')),
  173.       'ZAR' => array(array('rand'), array('cent'))
  174.     );
  175.  
  176.     /**
  177.      * The default currency name
  178.      * @var string
  179.      * @access public
  180.      */
  181.     var $def_currency = 'GBP'; // English pound
  182.  
  183.     // }}}
  184.     // {{{ toWords()
  185.  
  186.     /**
  187.      * Converts a number to its word representation
  188.      * in British English language
  189.      *
  190.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  191.      *                        that need to be converted to words
  192.      * @param  integer $power The power of ten for the rest of the number to the right.
  193.      *                        Optional, defaults to 0.
  194.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  195.      *                        Used internally. Optional, defaults to ''.
  196.      *
  197.      * @return string  The corresponding word representation
  198.      *
  199.      * @access public
  200.      * @author Piotr Klaban <makler@man.torun.pl>
  201.      * @since  PHP 4.2.3
  202.      */
  203.     function toWords($num, $power = 0, $powsuffix = '') {
  204.       $ret = '';        
  205.         
  206.       // add a minus sign
  207.       if (substr($num, 0, 1) == '-') {
  208.         $ret = $this->_sep . $this->_minus;
  209.         $num = substr($num, 1);
  210.       }
  211.         
  212.       // strip excessive zero signs and spaces
  213.       $num = trim($num);
  214.       $num = preg_replace('/^0+/','',$num);
  215.         
  216.       if (strlen($num) > 3) {
  217.           $maxp = strlen($num)-1;
  218.           $curp = $maxp;
  219.           for ($p = $maxp; $p > 0; --$p) { // power
  220.             
  221.             // check for highest power
  222.             if (isset($this->_exponent[$p])) {
  223.               // send substr from $curp to $p
  224.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  225.               $snum = preg_replace('/^0+/','',$snum);
  226.               if ($snum !== '') {
  227.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  228.                   if ($powsuffix != '')
  229.                     $cursuffix .= $this->_sep . $powsuffix;
  230.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  231.               }
  232.               $curp = $p - 1;
  233.               continue;
  234.             }
  235.           }
  236.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  237.           if ($num == 0) {
  238.               return $ret;
  239.           }
  240.       } elseif ($num == 0 || $num == '') {
  241.         return $this->_sep . $this->_digits[0];
  242.       }
  243.     
  244.       $h = $t = $d = 0;
  245.       
  246.       switch(strlen($num)) {
  247.         case 3:
  248.           $h = (int)substr($num,-3,1);
  249.  
  250.         case 2:
  251.           $t = (int)substr($num,-2,1);
  252.  
  253.         case 1:
  254.           $d = (int)substr($num,-1,1);
  255.           break;
  256.  
  257.         case 0:
  258.           return;
  259.           break;
  260.       }
  261.  
  262.       if ($h) {
  263.         $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundred';
  264.  
  265.         // in English only - add ' and' for [1-9]01..[1-9]99
  266.         // (also for 1001..1099, 10001..10099 but it is harder)
  267.         // for now it is switched off, maybe some language purists
  268.         // can force me to enable it, or to remove it completely
  269.         // if (($t + $d) > 0)
  270.         //   $ret .= $this->_sep . 'and';
  271.       }
  272.  
  273.       // ten, twenty etc.
  274.       switch ($t) {
  275.       case 9:
  276.       case 7:
  277.       case 6:
  278.           $ret .= $this->_sep . $this->_digits[$t] . 'ty';
  279.           break;
  280.     
  281.       case 8:
  282.           $ret .= $this->_sep . 'eighty';
  283.           break;
  284.     
  285.       case 5:
  286.           $ret .= $this->_sep . 'fifty';
  287.           break;
  288.     
  289.       case 4:
  290.           $ret .= $this->_sep . 'forty';
  291.           break;
  292.     
  293.       case 3:
  294.           $ret .= $this->_sep . 'thirty';
  295.           break;
  296.     
  297.       case 2:
  298.           $ret .= $this->_sep . 'twenty';
  299.           break;
  300.     
  301.       case 1:
  302.           switch ($d) {
  303.           case 0:
  304.               $ret .= $this->_sep . 'ten';
  305.               break;
  306.     
  307.           case 1:
  308.               $ret .= $this->_sep . 'eleven';
  309.               break;
  310.     
  311.           case 2:
  312.               $ret .= $this->_sep . 'twelve';
  313.               break;
  314.     
  315.           case 3:
  316.               $ret .= $this->_sep . 'thirteen';
  317.               break;
  318.     
  319.           case 4:
  320.           case 6:
  321.           case 7:
  322.           case 9:
  323.               $ret .= $this->_sep . $this->_digits[$d] . 'teen';
  324.               break;
  325.     
  326.           case 5:
  327.               $ret .= $this->_sep . 'fifteen';
  328.               break;
  329.     
  330.           case 8:
  331.               $ret .= $this->_sep . 'eighteen';
  332.               break;
  333.           }
  334.           break; 
  335.       }
  336.  
  337.       if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
  338.         // add minus sign between [2-9] and digit
  339.         if ($t > 1) {
  340.           $ret .= '-' . $this->_digits[$d];
  341.         } else {
  342.           $ret .= $this->_sep . $this->_digits[$d];
  343.         }
  344.       }
  345.   
  346.       if ($power > 0) {
  347.         if (isset($this->_exponent[$power]))
  348.           $lev = $this->_exponent[$power];
  349.     
  350.         if (!isset($lev) || !is_array($lev))
  351.           return null;
  352.      
  353.         $ret .= $this->_sep . $lev[0];
  354.       }
  355.     
  356.       if ($powsuffix != '')
  357.         $ret .= $this->_sep . $powsuffix;
  358.     
  359.       return $ret;
  360.     }
  361.     // }}}
  362.     // {{{ toCurrencyWords()
  363.  
  364.     /**
  365.      * Converts a currency value to its word representation
  366.      * (with monetary units) in English language
  367.      *
  368.      * @param  integer $int_curr An international currency symbol
  369.      *                 as defined by the ISO 4217 standard (three characters)
  370.      * @param  integer $decimal A money total amount without fraction part (e.g. amount of dollars)
  371.      * @param  integer $fraction Fractional part of the money amount (e.g. amount of cents)
  372.      *                 Optional. Defaults to false.
  373.      * @param  integer $convert_fraction Convert fraction to words (left as numeric if set to false).
  374.      *                 Optional. Defaults to true.
  375.      *
  376.      * @return string  The corresponding word representation for the currency
  377.      *
  378.      * @access public
  379.      * @author Piotr Klaban <makler@man.torun.pl>
  380.      * @since  Numbers_Words 0.13.1
  381.      */
  382.     function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) {
  383.         $int_curr = strtoupper($int_curr);
  384.         if (!isset($this->_currency_names[$int_curr])) {
  385.             $int_curr = $this->def_currency;
  386.         }
  387.         $curr_names = $this->_currency_names[$int_curr];
  388.         $ret  = trim($this->toWords($decimal));
  389.         $lev  = ($decimal == 1) ? 0 : 1;
  390.         if ($lev > 0) {
  391.             if (count($curr_names[0]) > 1) {
  392.                 $ret .= $this->_sep . $curr_names[0][$lev];
  393.             } else {
  394.                 $ret .= $this->_sep . $curr_names[0][0] . 's';
  395.             }
  396.         } else {
  397.             $ret .= $this->_sep . $curr_names[0][0];
  398.         }
  399.       
  400.         if ($fraction !== false) {
  401.             if ($convert_fraction) {
  402.                 $ret .= $this->_sep . trim($this->toWords($fraction));
  403.             } else {
  404.                 $ret .= $this->_sep . $fraction;
  405.             }
  406.             $lev  = ($fraction == 1) ? 0 : 1;
  407.             if ($lev > 0) {
  408.                 if (count($curr_names[1]) > 1) {
  409.                     $ret .= $this->_sep . $curr_names[1][$lev];
  410.                 } else {
  411.                     $ret .= $this->_sep . $curr_names[1][0] . 's';
  412.                 }
  413.             } else {
  414.                 $ret .= $this->_sep . $curr_names[1][0];
  415.             }
  416.         }
  417.         return $ret;
  418.     }
  419.     // }}}
  420.  
  421.  
  422. }
  423.  
  424. ?>
  425.