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.fr_BE.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  12.1 KB  |  418 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Kouber Saparev <kouber@php.net>                         |
  17. // |          Philippe Bajoit <phil@lebutch.org>                          |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: lang.fr_BE.php,v 1.1 2005/01/11 14:30:34 makler Exp $
  21.  
  22. /**
  23.  * Include needed files
  24.  */
  25. require_once("Numbers/Words.php");
  26.  
  27. /**
  28.  * Class for translating numbers into French (Belgium).
  29.  *
  30.  * @author Kouber Saparev <kouber@php.net> 
  31.  * @package Numbers_Words
  32.  */
  33. class Numbers_Words_fr_BE extends Numbers_Words
  34. {
  35.  
  36.     // {{{ properties
  37.  
  38.     /**
  39.      * Locale name.
  40.      * @var string
  41.      * @access public
  42.      */
  43.     var $locale      = 'fr';
  44.  
  45.     /**
  46.      * Language name in English.
  47.      * @var string
  48.      * @access public
  49.      */
  50.     var $lang        = 'French';
  51.  
  52.     /**
  53.      * Native language name.
  54.      * @var string
  55.      * @access public
  56.      */
  57.     var $lang_native = 'Franτais';
  58.  
  59.     /**
  60.      * The words for some numbers.
  61.      * @var string
  62.      * @access private
  63.      */
  64.     var $_misc_numbers = array(
  65.         10=>'dix',      // 10
  66.             'onze',     // 11
  67.             'douze',    // 12
  68.             'treize',   // 13
  69.             'quatorze', // 14
  70.             'quinze',   // 15
  71.             'seize',    // 16
  72.         20=>'vingt',    // 20
  73.         30=>'trente',   // 30
  74.         40=>'quarante', // 40
  75.         50=>'cinquante',// 50
  76.         60=>'soixante', // 60
  77.         70=>'septante', // 70
  78.         80=>'quatre-vingt', // 80
  79.         90=>'nonante',  // 90
  80.        100=>'cent'      // 100
  81.     );
  82.  
  83.  
  84.     /**
  85.      * The words for digits (except zero).
  86.      * @var string
  87.      * @access private
  88.      */
  89.     var $_digits = array(1=>"un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf");
  90.  
  91.     /**
  92.      * The word for zero.
  93.      * @var string
  94.      * @access private
  95.      */
  96.     var $_zero = 'zΘro';
  97.  
  98.     /**
  99.      * The word for infinity.
  100.      * @var string
  101.      * @access private
  102.      */
  103.     var $_infinity = 'infini';
  104.  
  105.     /**
  106.      * The word for the "and" language construct.
  107.      * @var string
  108.      * @access private
  109.      */
  110.     var $_and = 'et';
  111.     
  112.     /**
  113.      * The word separator.
  114.      * @var string
  115.      * @access private
  116.      */
  117.     var $_sep = ' ';
  118.  
  119.     /**
  120.      * The dash liaison.
  121.      * @var string
  122.      * @access private
  123.      */
  124.     var $_dash = '-';
  125.  
  126.     /**
  127.      * The word for the minus sign.
  128.      * @var string
  129.      * @access private
  130.      */
  131.     var $_minus = 'moins'; // minus sign
  132.  
  133.     /**
  134.      * The plural suffix (except for hundred).
  135.      * @var string
  136.      * @access private
  137.      */
  138.     var $_plural = 's'; // plural suffix
  139.  
  140.     /**
  141.      * The suffixes for exponents (singular).
  142.      * @var array
  143.      * @access private
  144.      */
  145.     var $_exponent = array(
  146.         0 => '',
  147.         3 => 'mille',
  148.         6 => 'million',
  149.         9 => 'milliard',
  150.        12 => 'trillion',
  151.        15 => 'quadrillion',
  152.        18 => 'quintillion',
  153.        21 => 'sextillion',
  154.        24 => 'septillion',
  155.        27 => 'octillion',
  156.        30 => 'nonillion',
  157.        33 => 'decillion',
  158.        36 => 'undecillion',
  159.        39 => 'duodecillion',
  160.        42 => 'tredecillion',
  161.        45 => 'quattuordecillion',
  162.        48 => 'quindecillion',
  163.        51 => 'sexdecillion',
  164.        54 => 'septendecillion',
  165.        57 => 'octodecillion',
  166.        60 => 'novemdecillion',
  167.        63 => 'vigintillion',
  168.        66 => 'unvigintillion',
  169.        69 => 'duovigintillion',
  170.        72 => 'trevigintillion',
  171.        75 => 'quattuorvigintillion',
  172.        78 => 'quinvigintillion',
  173.        81 => 'sexvigintillion',
  174.        84 => 'septenvigintillion',
  175.        87 => 'octovigintillion',
  176.        90 => 'novemvigintillion',
  177.        93 => 'trigintillion',
  178.        96 => 'untrigintillion',
  179.        99 => 'duotrigintillion',
  180.       102 => 'trestrigintillion',
  181.       105 => 'quattuortrigintillion',
  182.       108 => 'quintrigintillion',
  183.       111 => 'sextrigintillion',
  184.       114 => 'septentrigintillion',
  185.       117 => 'octotrigintillion',
  186.       120 => 'novemtrigintillion',
  187.       123 => 'quadragintillion',
  188.       126 => 'unquadragintillion',
  189.       129 => 'duoquadragintillion',
  190.       132 => 'trequadragintillion',
  191.       135 => 'quattuorquadragintillion',
  192.       138 => 'quinquadragintillion',
  193.       141 => 'sexquadragintillion',
  194.       144 => 'septenquadragintillion',
  195.       147 => 'octoquadragintillion',
  196.       150 => 'novemquadragintillion',
  197.       153 => 'quinquagintillion',
  198.       156 => 'unquinquagintillion',
  199.       159 => 'duoquinquagintillion',
  200.       162 => 'trequinquagintillion',
  201.       165 => 'quattuorquinquagintillion',
  202.       168 => 'quinquinquagintillion',
  203.       171 => 'sexquinquagintillion',
  204.       174 => 'septenquinquagintillion',
  205.       177 => 'octoquinquagintillion',
  206.       180 => 'novemquinquagintillion',
  207.       183 => 'sexagintillion',
  208.       186 => 'unsexagintillion',
  209.       189 => 'duosexagintillion',
  210.       192 => 'tresexagintillion',
  211.       195 => 'quattuorsexagintillion',
  212.       198 => 'quinsexagintillion',
  213.       201 => 'sexsexagintillion',
  214.       204 => 'septensexagintillion',
  215.       207 => 'octosexagintillion',
  216.       210 => 'novemsexagintillion',
  217.       213 => 'septuagintillion',
  218.       216 => 'unseptuagintillion',
  219.       219 => 'duoseptuagintillion',
  220.       222 => 'treseptuagintillion',
  221.       225 => 'quattuorseptuagintillion',
  222.       228 => 'quinseptuagintillion',
  223.       231 => 'sexseptuagintillion',
  224.       234 => 'septenseptuagintillion',
  225.       237 => 'octoseptuagintillion',
  226.       240 => 'novemseptuagintillion',
  227.       243 => 'octogintillion',
  228.       246 => 'unoctogintillion',
  229.       249 => 'duooctogintillion',
  230.       252 => 'treoctogintillion',
  231.       255 => 'quattuoroctogintillion',
  232.       258 => 'quinoctogintillion',
  233.       261 => 'sexoctogintillion',
  234.       264 => 'septoctogintillion',
  235.       267 => 'octooctogintillion',
  236.       270 => 'novemoctogintillion',
  237.       273 => 'nonagintillion',
  238.       276 => 'unnonagintillion',
  239.       279 => 'duononagintillion',
  240.       282 => 'trenonagintillion',
  241.       285 => 'quattuornonagintillion',
  242.       288 => 'quinnonagintillion',
  243.       291 => 'sexnonagintillion',
  244.       294 => 'septennonagintillion',
  245.       297 => 'octononagintillion',
  246.       300 => 'novemnonagintillion',
  247.       303 => 'centillion'
  248.         );
  249.     // }}}
  250.  
  251.     // {{{ _splitNumber()
  252.  
  253.     /**
  254.      * Split a number to groups of three-digit numbers.
  255.      *
  256.      * @param  mixed  $num   An integer or its string representation
  257.      *                       that need to be split
  258.      *
  259.      * @return array  Groups of three-digit numbers.
  260.      *
  261.      * @access private
  262.      * @author Kouber Saparev <kouber@php.net>
  263.      * @since  PHP 4.2.3
  264.      */
  265.  
  266.     function _splitNumber($num)
  267.     {
  268.         if (is_string($num)) {
  269.             $ret = array();
  270.             $strlen = strlen($num);
  271.             $first = substr($num, 0, $strlen%3);
  272.             preg_match_all('/\d{3}/', substr($num, $strlen%3, $strlen), $m);
  273.             $ret =& $m[0];
  274.             if ($first) array_unshift($ret, $first);
  275.             return $ret;
  276.         }
  277.         else
  278.             return explode(' ', number_format($num, 0, '', ' ')); // a faster version for integers
  279.     }
  280.     // }}}
  281.  
  282.     // {{{ _showDigitsGroup()
  283.  
  284.     /**
  285.      * Converts a three-digit number to its word representation
  286.      * in French language.
  287.      *
  288.      * @param  integer  $num     An integer between 1 and 999 inclusive.
  289.      *
  290.      * @param  boolean  $last    A flag, that determines if it is the last group of digits -
  291.      *                           this is used to accord the plural suffix of the "hundreds".
  292.      *                           Example: 200 = "deux cents", but 200000 = "deux cent mille".
  293.      *
  294.      *
  295.      * @return string   The words for the given number.
  296.      *
  297.      * @access private
  298.      * @author Kouber Saparev <kouber@php.net>
  299.      */
  300.     function _showDigitsGroup($num, $last = false)
  301.     {
  302.         $ret = '';
  303.         
  304.         // extract the value of each digit from the three-digit number
  305.         $e = $num%10;                  // ones
  306.         $d = ($num-$e)%100/10;         // tens
  307.         $s = ($num-$d*10-$e)%1000/100; // hundreds
  308.         
  309.         // process the "hundreds" digit.
  310.         if ($s) {
  311.             if ($s>1) {
  312.                 $ret .= $this->_digits[$s].$this->_sep.$this->_misc_numbers[100];
  313.                 if ($last && !$e && !$d) {
  314.                     $ret .= $this->_plural;
  315.                 }
  316.             } else {
  317.                 $ret .= $this->_misc_numbers[100];
  318.             }
  319.             $ret .= $this->_sep;
  320.         }
  321.  
  322.         // process the "tens" digit, and optionally the "ones" digit.
  323.         if ($d) {
  324.             // in the case of 1, the "ones" digit also must be processed
  325.             if ($d==1) {
  326.                 if ($e<=6) {
  327.                     $ret .= $this->_misc_numbers[10+$e];
  328.                 } else {
  329.                     $ret .= $this->_misc_numbers[10].'-'.$this->_digits[$e];
  330.                 }
  331.                 $e = 0;
  332.             } else {
  333.                 $ret .= $this->_misc_numbers[$d*10];
  334.             }
  335.         }
  336.  
  337.         // process the "ones" digit
  338.         if ($e) {
  339.             if ($d) {
  340.                 if ($e==1) {
  341.                     $ret .= $this->_sep.$this->_and.$this->_sep;
  342.                 } else {
  343.                     $ret .= $this->_dash;
  344.                 }
  345.             }
  346.             $ret .= $this->_digits[$e];
  347.         }
  348.  
  349.         // strip excessive separators
  350.         $ret = rtrim($ret, $this->_sep);
  351.  
  352.         return $ret;
  353.     }
  354.     // }}}
  355.  
  356.     // {{{ toWords()
  357.  
  358.     /**
  359.      * Converts a number to its word representation
  360.      * in French language.
  361.      *
  362.      * @param  integer $num   An integer (or its string representation) between 9.99*-10^302
  363.      *                        and 9.99*10^302 (999 centillions) that need to be converted to words
  364.      *
  365.      * @return string  The corresponding word representation
  366.      *
  367.      * @access public
  368.      * @author Kouber Saparev <kouber@php.net>
  369.      */
  370.     function toWords($num = 0)
  371.     {
  372.         $ret = '';
  373.  
  374.         // check if $num is a valid non-zero number
  375.         if (!$num || preg_match('/^-?0+$/', $num) || !preg_match('/^-?\d+$/', $num)) return $this->_zero;
  376.  
  377.         // add a minus sign
  378.         if (substr($num, 0, 1) == '-') {
  379.             $ret = $this->_minus . $this->_sep;
  380.             $num = substr($num, 1);
  381.         }
  382.  
  383.         // if the absolute value is greater than 9.99*10^302, return infinity
  384.         if (strlen($num)>306) {
  385.             return $ret . $this->_infinity;
  386.         }
  387.  
  388.         // strip excessive zero signs
  389.         $num = ltrim($num, '0');
  390.  
  391.         // split $num to groups of three-digit numbers
  392.         $num_groups = $this->_splitNumber($num);
  393.  
  394.         $sizeof_numgroups = count($num_groups);
  395.  
  396.         foreach ($num_groups as $i=>$number) {
  397.             // what is the corresponding exponent for the current group
  398.             $pow = $sizeof_numgroups-$i;
  399.  
  400.             // skip processment for empty groups
  401.             if ($number!='000') {
  402.                 if ($number!=1 || $pow!=2) {
  403.                     $ret .= $this->_showDigitsGroup($number, $i+1==$sizeof_numgroups).$this->_sep;
  404.                 }
  405.                 $ret .= $this->_exponent[($pow-1)*3];
  406.                 if ($pow>2 && $number>1) {
  407.                     $ret .= $this->_plural;
  408.                 }
  409.                 $ret .= $this->_sep;
  410.             }
  411.         }
  412.  
  413.         return rtrim($ret, $this->_sep);
  414.     }
  415.     // }}}
  416. }
  417. ?>
  418.