Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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