Numbers_Words
[ class tree: Numbers_Words ] [ index: Numbers_Words ] [ all elements ]

Source for file lang.fr.php

Documentation is available at lang.fr.php

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

Documentation generated on Mon, 11 Mar 2019 13:56:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.