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   Piotr Klaban <makler@man.torun.pl>
20
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
21
 * @version  CVS: $Id: lang.nl.php 269651 2008-11-25 03:48:32Z clockwerx $
22
 * @link     http://pear.php.net/package/Numbers_Words
23
 */
24
 
25
/**
26
 *
27
 * Class for translating numbers into Dutch.
28
 * @author Piotr Klaban
29
 * @author WHAM van Dinter (for Dutch Translations)
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 Dutch.
40
 *
41
 * @category Numbers
42
 * @package  Numbers_Words
43
 * @author   Piotr Klaban <makler@man.torun.pl>
44
 * @author   WHAM van Dinter (for Dutch Translations)
45
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
46
 * @link     http://pear.php.net/package/Numbers_Words
47
 */
48
class Numbers_Words_nl extends Numbers_Words
49
{
50
 
51
    // {{{ properties
52
 
53
    /**
54
     * Locale name
55
     * @var string
56
     * @access public
57
     */
58
    var $locale = 'nl';
59
 
60
    /**
61
     * Language name in English
62
     * @var string
63
     * @access public
64
     */
65
    var $lang = 'Dutch';
66
 
67
    /**
68
     * Native language name
69
     * @var string
70
     * @access public
71
     */
72
    var $lang_native = 'Nederlands';
73
 
74
    /**
75
     * The word for the minus sign
76
     * @var string
77
     * @access private
78
     */
79
    var $_minus = 'Minus'; // minus sign
80
 
81
    /**
82
     * The sufixes for exponents (singular and plural)
83
     * Names partly based on:
84
     * http://nl.wikipedia.org/wiki/Quadriljoen
85
     * @var array
86
     * @access private
87
     */
88
    var $_exponent = array(
89
 
90
        3 => array('Duizend','Duizend'),
91
        6 => array('Miljoen','Miljoen'),
92
        9 => array('Miljard','Miljard'),
93
       12 => array('Biljoen','Biljoen'),
94
       15 => array('Biljard','Biljard'),
95
       18 => array('Triljoen','Triljoen'),
96
       21 => array('Triljard','Triljard'),
97
       24 => array('Quadriljoen','Quadriljoen'),
98
       27 => array('Quadriljard','Quadriljard'),
99
       30 => array('Quintiljoen','Quintiljoen'),
100
       33 => array('Quintiljard','Quintiljard'),
101
       36 => array('Sextiljoen','Sextiljoen'),
102
       39 => array('Sextiljard','Sextiljard'),
103
       42 => array('Septiljoen','Septiljoen'),
104
       45 => array('Septiljard','Septiljard'),
105
       48 => array('Octiljoen','Octiljoen'),
106
       51 => array('Octiljard','Octiljard'),
107
       54 => array('Noniljoen','Noniljoen'),
108
       57 => array('Noniljard','Noniljard'),
109
       60 => array('Deciljoen','Deciljoen'),
110
       63 => array('Deciljard','Deciljard'),
111
       66 => array('Undeciljoen','Undeciljoen'),
112
       69 => array('Undeciljard','Undeciljard'),
113
       72 => array('Duodeciljoen','Duodeciljoen'),
114
       75 => array('Duodeciljard','Duodeciljard'),
115
       78 => array('Tredeciljoen','Tredeciljoen'),
116
       81 => array('Tredeciljard','Tredeciljard'),
117
      120 => array('Vigintiljoen','Vigintiljoen'),
118
      123 => array('Vigintiljard','Vigintiljard'),
119
      600 => array('Zentiljoen','Zentiljoen'), // oder Centillion
120
      603 => array('Zentiljardn','Zentiljard')
121
        );
122
 
123
    /**
124
     * The array containing the digits (indexed by the digits themselves).
125
     * @var array
126
     * @access private
127
     */
128
    var $_digits = array(
129
 
130
        'vijf', 'zes', 'zeven', 'acht', 'negen'
131
    );
132
 
133
    /**
134
     * The word separator
135
     * @var string
136
     * @access private
137
     */
138
    var $_sep = '';
139
 
140
    /**
141
     * The exponent word separator
142
     * @var string
143
     * @access private
144
     */
145
    var $_sep2 = '-';
146
 
147
    // }}}
148
    // {{{ toWords()
149
 
150
    /**
151
     * Converts a number to its word representation
152
     * in Dutch language.
153
     *
154
     * @param integer $num       An integer between -infinity and infinity inclusive :)
155
     *                           that need to be converted to words
156
     * @param integer $power     The power of ten for the rest of the number to the right.
157
     *                           Optional, defaults to 0.
158
     * @param integer $powsuffix The power name to be added to the end of the return string.
159
     *                            Used internally. Optional, defaults to ''.
160
     *
161
     * @return string  The corresponding word representation
162
     *
163
     * @access public
164
     * @author Piotr Klaban <makler@man.torun.pl>
165
     * @author WHAM van Dinter <willem@fkkc.nl>
166
     * @since  PHP 4.2.3
167
     */
168
    function toWords($num, $power = 0, $powsuffix = '')
169
    {
170
        $ret = '';
171
 
172
        // add a minus sign
173
        if (substr($num, 0, 1) == '-') {
174
            $ret = $this->_sep . $this->_minus;
175
            $num = substr($num, 1);
176
        }
177
 
178
        // strip excessive zero signs and spaces
179
        $num = trim($num);
180
        $num = preg_replace('/^0+/', '', $num);
181
 
182
        if (strlen($num) > 3) {
183
            $maxp = strlen($num)-1;
184
            $curp = $maxp;
185
            for ($p = $maxp; $p > 0; --$p) { // power
186
 
187
                // check for highest power
188
                if (isset($this->_exponent[$p])) {
189
                    // send substr from $curp to $p
190
                    $snum = substr($num, $maxp - $curp, $curp - $p + 1);
191
                    $snum = preg_replace('/^0+/', '', $snum);
192
                    if ($snum !== '') {
193
                        $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
194
                        if ($powsuffix != '') {
195
                            $cursuffix .= $this->_sep . $powsuffix;
196
                        }
197
 
198
                        $ret .= $this->toWords($snum, $p, $cursuffix);
199
                    }
200
                    $curp = $p - 1;
201
                    continue;
202
                }
203
            }
204
            $num = substr($num, $maxp - $curp, $curp - $p + 1);
205
            if ($num == 0) {
206
                return $ret;
207
            }
208
        } elseif ($num == 0 || $num == '') {
209
            return $this->_sep . $this->_digits[0];
210
        }
211
 
212
        $h = $t = $d = 0;
213
 
214
        switch(strlen($num)) {
215
        case 3:
216
            $h = (int)substr($num, -3, 1);
217
 
218
        case 2:
219
            $t = (int)substr($num, -2, 1);
220
 
221
        case 1:
222
            $d = (int)substr($num, -1, 1);
223
            break;
224
 
225
        case 0:
226
            return;
227
            break;
228
        }
229
 
230
        if ($h) {
231
            $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'honderd';
232
        }
233
 
234
         // add digits only in <0>,<1,9> and <21,inf>
235
        if ($t != 1 && $d > 0) {
236
            if ($t > 0) {
237
                $ret .= $this->_digits[$d] . 'en';
238
            } else {
239
                $ret .= $this->_digits[$d];
240
                if ($d == 1) {
241
                    if ($power == 0) {
242
                        $ret .= 's'; // fuer eins
243
                    } else {
244
                        if ($power != 3) {  // tausend ausnehmen
245
                            $ret .= ''; // fuer eine
246
                        }
247
                    }
248
                }
249
            }
250
        }
251
 
252
        // ten, twenty etc.
253
        switch ($t) {
254
        case 9:
255
        case 8:
256
        case 7:
257
        case 6:
258
        case 5:
259
            $ret .= $this->_sep . $this->_digits[$t] . 'tig';
260
            break;
261
 
262
        case 4:
263
            $ret .= $this->_sep . 'veertig';
264
            break;
265
 
266
        case 3:
267
            $ret .= $this->_sep . 'dertig';
268
            break;
269
 
270
        case 2:
271
            $ret .= $this->_sep . 'twintig';
272
            break;
273
 
274
        case 1:
275
            switch ($d) {
276
            case 0:
277
                $ret .= $this->_sep . 'tien';
278
                break;
279
 
280
            case 1:
281
                $ret .= $this->_sep . 'elf';
282
                break;
283
 
284
            case 2:
285
                $ret .= $this->_sep . 'twaalf';
286
                break;
287
 
288
            case 3:
289
                $ret .= $this->_sep . 'dertien';
290
                break;
291
 
292
            case 4:
293
                $ret .= $this->_sep . 'veertien';
294
                break;
295
 
296
            case 5:
297
            case 6:
298
            case 7:
299
            case 8:
300
            case 9:
301
                $ret .= $this->_sep . $this->_digits[$d] . 'tien';
302
                break;
303
 
304
            }
305
            break;
306
        }
307
 
308
        if ($power > 0) {
309
            if (isset($this->_exponent[$power])) {
310
                $lev = $this->_exponent[$power];
311
            }
312
 
313
            if (!isset($lev) || !is_array($lev)) {
314
                return null;
315
            }
316
 
317
            if ($power == 3) {
318
                $ret .= $this->_sep . $lev[0];
319
            } elseif ($d == 1 && ($t+$h) == 0) {
320
                $ret .= $this->_sep2 . $lev[0] . $this->_sep2;
321
            } else {
322
                $ret .= $this->_sep2 . $lev[1] . $this->_sep2;
323
            }
324
        }
325
 
326
        if ($powsuffix != '') {
327
            $ret .= $this->_sep . $powsuffix;
328
        }
329
 
330
        return $ret;
331
    }
332
    // }}}
333
}
334
 
335
?>