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   Petr 'PePa' Pavel <petr.pavel@pepa.info>
20
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
21
 * @version  CVS: $Id: lang.cs.php 269648 2008-11-25 02:45:52Z clockwerx $
22
 * @link     http://pear.php.net/package/Numbers_Words
23
 */
24
 
25
/**
26
 * Class for translating numbers into Czech.
27
 *
28
 * @author Petr 'PePa' Pavel
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 Czech.
39
 *
40
 * @category Numbers
41
 * @package  Numbers_Words
42
 * @author   Petr 'PePa' Pavel <petr.pavel@pepa.info>
43
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
44
 * @link     http://pear.php.net/package/Numbers_Words
45
 */
46
class Numbers_Words_cs extends Numbers_Words
47
{
48
 
49
    // {{{ properties
50
 
51
    /**
52
     * Locale name
53
     * @var string
54
     * @access public
55
     */
56
    var $locale = 'cs';
57
 
58
    /**
59
     * Language name in English
60
     * @var string
61
     * @access public
62
     */
63
    var $lang = 'Czech';
64
 
65
    /**
66
     * Native language name
67
     * @var string
68
     * @access public
69
     */
70
    var $lang_native = 'Czech';
71
 
72
    /**
73
     * The word for the minus sign
74
     * @var string
75
     * @access private
76
     */
77
    var $_minus = 'mínus'; // minus sign
78
 
79
    /**
80
     * The sufixes for exponents (singular and plural)
81
     * Names partly based on:
82
     * http://cs.wikipedia.org/wiki/P%C5%99edpony_soustavy_SI
83
     * the rest was translated from lang.en_GB.php
84
     * names verified by "Ustav pro jazyk cesky" only up to Septilion
85
     * (they could verify only the lingual matter - not the mathematical one)
86
     * @var array
87
     * @access private
88
     */
89
    var $_exponent = array(
90
 
91
        3 => array('tisíc','tisíce','tisíc'),
92
        6 => array('milion','miliony','milionù'),
93
        9 => array('miliarda','miliardy','miliard'),
94
       12 => array('bilion','biliony','bilionù'),
95
       15 => array('biliarda','biliardy','biliard'),
96
       18 => array('trilion','triliony','trilionù'),
97
       21 => array('triliarda','triliardy','triliard'),
98
 
99
       24 => array('kvadrilion','kvadriliony','kvadrilionù'),
100
       30 => array('kvintilion','kvintiliony','kvintilionù'),
101
       36 => array('sextilion','sextiliony','sextilionù'),
102
       42 => array('septilion','septiliony','septilionù'),
103
 
104
       48 => array('oktilion','oktiliony','oktilionù'),
105
       54 => array('nonilion','noniliony','nonilionù'),
106
       60 => array('decilion','deciliony','decilionù'),
107
 
108
       66 => array('undecilion','undeciliony','undecilionù'),
109
       72 => array('duodecilion','duodeciliony','duodecilionù'),
110
       78 => array('tredecilion','tredeciliony','tredecilionù'),
111
       84 => array('kvatrodecilion','kvatrodeciliony','kvatrodecilionù'),
112
       90 => array('kvindecilion','kvindeciliony','kvindecilionù'),
113
       96 => array('sexdecilion','sexdeciliony','sexdecilionù'),
114
      102 => array('septendecilion','septendeciliony','septendecilionù'),
115
      108 => array('oktodecilion','oktodeciliony','oktodecilionù'),
116
      114 => array('novemdecilion','novemdeciliony','novemdecilionù'),
117
      120 => array('vigintilion','vigintiliony','vigintilionù'),
118
      192 => array('duotrigintilion','duotrigintiliony','duotrigintilionù'),
119
      600 => array('centilion','centiliony','centilionù')
120
 
121
        );
122
 
123
    /**
124
     * The array containing the forms of Czech word for "hundred"
125
     * @var array
126
     * @access private
127
     */
128
    var $_hundreds = array(
129
 
130
    );
131
 
132
    /**
133
     * The array containing the digits (indexed by the digits themselves).
134
     * @var array
135
     * @access private
136
     */
137
    var $_digits = array(
138
 
139
        'pìt', '¹est', 'sedm', 'osm', 'devìt'
140
    );
141
 
142
    /**
143
     * The word separator
144
     * @var string
145
     * @access private
146
     */
147
    var $_sep = ' ';
148
 
149
    // }}}
150
    // {{{ toWords()
151
 
152
    /**
153
     * Converts a number to its word representation
154
     * in Czech language
155
     *
156
     * @param integer $num       An integer between -infinity and infinity inclusive :)
157
     *                           that need to be converted to words
158
     * @param integer $power     The power of ten for the rest of the number to the right.
159
     *                           Optional, defaults to 0.
160
     * @param integer $powsuffix The power name to be added to the end of the return string.
161
     *                            Used internally. Optional, defaults to ''.
162
     *
163
     * @return string  The corresponding word representation
164
     *
165
     * @access public
166
     * @author Petr 'PePa' Pavel <petr.pavel@pepa.info>
167
     * @since  PHP 4.2.3
168
     */
169
    function toWords($num, $power = 0, $powsuffix = '')
170
    {
171
        $ret = '';
172
 
173
        // add a minus sign
174
        if (substr($num, 0, 1) == '-') {
175
            $ret = $this->_sep . $this->_minus;
176
            $num = substr($num, 1);
177
        }
178
 
179
        // strip excessive zero signs and spaces
180
        $num = trim($num);
181
        $num = preg_replace('/^0+/', '', $num);
182
 
183
        if (strlen($num) > 3) {
184
            $maxp = strlen($num)-1;
185
            $curp = $maxp;
186
            for ($p = $maxp; $p > 0; --$p) { // power
187
 
188
                // check for highest power
189
                if (isset($this->_exponent[$p])) {
190
                    // send substr from $curp to $p
191
                    $snum = substr($num, $maxp - $curp, $curp - $p + 1);
192
                    $snum = preg_replace('/^0+/', '', $snum);
193
                    if ($snum !== '') {
194
                        $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
195
                        if ($powsuffix != '') {
196
                            $cursuffix .= $this->_sep . $powsuffix;
197
                        }
198
 
199
                        $ret .= $this->toWords($snum, $p, $cursuffix);
200
                    }
201
                    $curp = $p - 1;
202
                    continue;
203
                }
204
            }
205
            $num = substr($num, $maxp - $curp, $curp - $p + 1);
206
            if ($num == 0) {
207
                return $ret;
208
            }
209
        } elseif ($num == 0 || $num == '') {
210
            return $this->_sep . $this->_digits[0];
211
        }
212
 
213
        $h = $t = $d = 0;
214
 
215
        switch(strlen($num)) {
216
        case 3:
217
            $h = (int)substr($num, -3, 1);
218
 
219
        case 2:
220
            $t = (int)substr($num, -2, 1);
221
 
222
        case 1:
223
            $d = (int)substr($num, -1, 1);
224
            break;
225
 
226
        case 0:
227
            return;
228
            break;
229
        }
230
 
231
        if ($h) {
232
 
233
            // inflection of the word "hundred"
234
            if ($h == 1) {
235
                $ret .= $this->_sep . $this->_hundreds[0];
236
            } elseif ($h == 2) {
237
                $ret .= $this->_sep . "dvì" . $this->_sep . $this->_hundreds[1];
238
            } elseif ( ($h > 1) && ($h < 5) ) {
239
                $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . $this->_hundreds[2];
240
            } else {		//if ($h >= 5)
241
                $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . $this->_hundreds[3];
242
            }
243
            // in English only - add ' and' for [1-9]01..[1-9]99
244
            // (also for 1001..1099, 10001..10099 but it is harder)
245
            // for now it is switched off, maybe some language purists
246
            // can force me to enable it, or to remove it completely
247
            // if (($t + $d) > 0)
248
            //   $ret .= $this->_sep . 'and';
249
        }
250
 
251
        // ten, twenty etc.
252
        switch ($t) {
253
        case 2:
254
        case 3:
255
        case 4:
256
            $ret .= $this->_sep . $this->_digits[$t] . 'cet';
257
            break;
258
 
259
        case 5:
260
            $ret .= $this->_sep . 'padesát';
261
            break;
262
 
263
        case 6:
264
            $ret .= $this->_sep . '¹edesát';
265
            break;
266
 
267
        case 7:
268
            $ret .= $this->_sep . 'sedmdesát';
269
            break;
270
 
271
        case 8:
272
            $ret .= $this->_sep . 'osmdesát';
273
            break;
274
 
275
        case 9:
276
            $ret .= $this->_sep . 'devadesát';
277
            break;
278
 
279
        case 1:
280
            switch ($d) {
281
            case 0:
282
                $ret .= $this->_sep . 'deset';
283
                break;
284
 
285
            case 1:
286
                $ret .= $this->_sep . 'jedenáct';
287
                break;
288
 
289
            case 4:
290
                $ret .= $this->_sep . 'ètrnáct';
291
                break;
292
 
293
            case 5:
294
                $ret .= $this->_sep . 'patnáct';
295
                break;
296
 
297
            case 9:
298
                $ret .= $this->_sep . 'devatenáct';
299
                break;
300
 
301
            case 2:
302
            case 3:
303
            case 6:
304
            case 7:
305
            case 8:
306
                $ret .= $this->_sep . $this->_digits[$d] . 'náct';
307
                break;
308
            }
309
            break;
310
        }
311
 
312
        if (($t != 1) && ($d > 0) && (($power == 0) || ($num > 1))) {
313
            $ret .= $this->_sep . $this->_digits[$d];
314
        }
315
 
316
        if ($power > 0) {
317
            if (isset($this->_exponent[$power])) {
318
                $lev = $this->_exponent[$power];
319
            }
320
 
321
            if (!isset($lev) || !is_array($lev)) {
322
                return null;
323
            }
324
 
325
            // inflection of exponental words
326
            if ($num == 1) {
327
                $idx = 0;
328
            } elseif ( (($num > 1) && ($num < 5)) || ((intval("$t$d") > 1) && (intval("$t$d") < 5))) {
329
                $idx = 1;
330
            } else {
331
                $idx = 2;
332
            }
333
 
334
            $ret .= $this->_sep . $lev[$idx];
335
        }
336
 
337
        if ($powsuffix != '') {
338
            $ret .= $this->_sep . $powsuffix;
339
        }
340
 
341
        return $ret;
342
    }
343
    // }}}
344
}
345
 
346
?>