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   Nils Homp
20
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
21
 * @version  CVS: $Id: lang.hu_HU.php 295960 2010-03-08 13:04:59Z clockwerx $
22
 * @link     http://pear.php.net/package/Numbers_Words
23
 */
24
 
25
// Numbers_Words class extension to spell numbers in Hungarian language.
26
// NOTE: toCurrency() was not localized and is from the en_US class.
27
//
28
 
29
/**
30
 * Class for translating numbers into Hungarian.
31
 *
32
 * @author Nils Homp
33
 * @package Numbers_Words
34
 */
35
 
36
/**
37
 * Include needed files
38
 */
39
require_once "Numbers/Words.php";
40
 
41
/**
42
 * Class for translating numbers into Hungarian.
43
 *
44
 * @category Numbers
45
 * @package  Numbers_Words
46
 * @author   Nils Homp
47
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
48
 * @link     http://pear.php.net/package/Numbers_Words
49
 */
50
class Numbers_Words_hu_HU extends Numbers_Words
51
{
52
 
53
    // {{{ properties
54
 
55
    /**
56
     * Locale name
57
     * @var string
58
     * @access public
59
     */
60
    var $locale = 'hu_HU';
61
 
62
    /**
63
     * Language name in English
64
     * @var string
65
     * @access public
66
     */
67
    var $lang = 'Hungarian';
68
 
69
    /**
70
     * Native language name
71
     * @var string
72
     * @access public
73
     */
74
    var $lang_native = 'Magyar';
75
 
76
    /**
77
     * The word for the minus sign
78
     * @var string
79
     * @access private
80
     */
81
    var $_minus = 'Minusz'; // minus sign
82
 
83
    /**
84
     * The sufixes for exponents (singular and plural)
85
     * Names based on:
86
     * http://mek.oszk.hu/adatbazis/lexikon/phplex/lexikon/d/kisokos/186.html
87
     * @var array
88
     * @access private
89
     */
90
    var $_exponent = array(
91
 
92
        3 => array('ezer'),
93
        6 => array('millió'),
94
        9 => array('milliárd'),
95
       12 => array('billió'),
96
       15 => array('billiárd'),
97
       18 => array('trillió'),
98
       21 => array('trilliárd'),
99
       24 => array('kvadrillió'),
100
       27 => array('kvadrilliárd'),
101
       30 => array('kvintillió'),
102
       33 => array('kvintilliárd'),
103
       36 => array('szextillió'),
104
       39 => array('szextilliárd'),
105
       42 => array('szeptillió'),
106
       45 => array('szeptilliárd'),
107
       48 => array('oktillió'),
108
       51 => array('oktilliárd'),
109
       54 => array('nonillió'),
110
       57 => array('nonilliárd'),
111
       60 => array('decillió'),
112
       63 => array('decilliárd'),
113
       600 => array('centillió')
114
        );
115
 
116
    /**
117
     * The array containing the digits (indexed by the digits themselves).
118
     * @var array
119
     * @access private
120
     */
121
    var $_digits = array(
122
 
123
        'öt', 'hat', 'hét', 'nyolc', 'kilenc'
124
    );
125
 
126
    /**
127
     * The word separator
128
     * @var string
129
     * @access private
130
     */
131
    var $_sep = '';
132
 
133
    /**
134
     * The currency names (based on the below links,
135
     * informations from central bank websites and on encyclopedias)
136
     *
137
     * @var array
138
     * @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
139
     * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
140
     * @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
141
     * @access private
142
     */
143
    var $_currency_names = array(
144
      'ALL' => array(array('lek'), array('qindarka')),
145
      'AUD' => array(array('Australian dollar'), array('cent')),
146
      'BAM' => array(array('convertible marka'), array('fenig')),
147
      'BGN' => array(array('lev'), array('stotinka')),
148
      'BRL' => array(array('real'), array('centavos')),
149
      'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
150
      'CAD' => array(array('Canadian dollar'), array('cent')),
151
      'CHF' => array(array('Swiss franc'), array('rapp')),
152
      'CYP' => array(array('Cypriot pound'), array('cent')),
153
      'CZK' => array(array('Czech koruna'), array('halerz')),
154
      'DKK' => array(array('Danish krone'), array('ore')),
155
      'EEK' => array(array('kroon'), array('senti')),
156
      'EUR' => array(array('euro'), array('euro-cent')),
157
      'GBP' => array(array('pound', 'pounds'), array('pence', 'pence')),
158
      'HKD' => array(array('Hong Kong dollar'), array('cent')),
159
      'HRK' => array(array('Croatian kuna'), array('lipa')),
160
      'HUF' => array(array('forint'), array('filler')),
161
      'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
162
      'ISK' => array(array('Icelandic króna'), array('aurar')),
163
      'JPY' => array(array('yen'), array('sen')),
164
      'LTL' => array(array('litas'), array('cent')),
165
      'LVL' => array(array('lat'), array('sentim')),
166
      'MKD' => array(array('Macedonian dinar'), array('deni')),
167
      'MTL' => array(array('Maltese lira'), array('centym')),
168
      'NOK' => array(array('Norwegian krone'), array('oere')),
169
      'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
170
      'ROL' => array(array('Romanian leu'), array('bani')),
171
      'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
172
      'SEK' => array(array('Swedish krona'), array('oere')),
173
      'SIT' => array(array('Tolar'), array('stotinia')),
174
      'SKK' => array(array('Slovak koruna'), array()),
175
      'TRL' => array(array('lira'), array('kuruþ')),
176
      'UAH' => array(array('hryvna'), array('cent')),
177
      'USD' => array(array('dollar'), array('cent')),
178
      'YUM' => array(array('dinars'), array('para')),
179
      'ZAR' => array(array('rand'), array('cent'))
180
    );
181
 
182
    /**
183
     * The default currency name
184
     * @var string
185
     * @access public
186
     */
187
    var $def_currency = 'HUF'; // forint
188
 
189
    // }}}
190
    // {{{ toWords()
191
 
192
    /**
193
     * Converts a number to its word representation
194
     * in the Hungarian language
195
     *
196
     * @param integer $num       An integer between -infinity and infinity inclusive :)
197
     *                           that need to be converted to words
198
     * @param integer $power     The power of ten for the rest of the number to the right.
199
     *                           Optional, defaults to 0.
200
     * @param integer $powsuffix The power name to be added to the end of the return string.
201
     *                           Used internally. Optional, defaults to ''.
202
     *
203
     * @return string  The corresponding word representation
204
     *
205
     * @access public
206
     * @author Nils Homp
207
     * @since  PHP 4.2.3
208
     */
209
    function toWords($num, $power = 0, $powsuffix = '')
210
    {
211
        $ret = '';
212
 
213
        // add a minus sign
214
        if (substr($num, 0, 1) == '-') {
215
            $ret = $this->_sep . $this->_minus;
216
            $num = substr($num, 1);
217
        }
218
 
219
        // strip excessive zero signs and spaces
220
        $num = trim($num);
221
        $num = preg_replace('/^0+/', '', $num);
222
 
223
        if (strlen($num) > 3) {
224
            $maxp = strlen($num)-1;
225
            $curp = $maxp;
226
            for ($p = $maxp; $p > 0; --$p) { // power
227
 
228
                // check for highest power
229
                if (isset($this->_exponent[$p])) {
230
                    // send substr from $curp to $p
231
                    $snum = substr($num, $maxp - $curp, $curp - $p + 1);
232
                    $snum = preg_replace('/^0+/', '', $snum);
233
                    if ($snum !== '') {
234
                        $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
235
                        if ($powsuffix != '') {
236
                            $cursuffix .= $this->_sep . $powsuffix;
237
                        }
238
 
239
                        $ret .= $this->toWords($snum, $p, $cursuffix);
240
                    }
241
                    $curp = $p - 1;
242
                    continue;
243
                }
244
            }
245
            $num = substr($num, $maxp - $curp, $curp - $p + 1);
246
            if ($num == 0) {
247
                return $ret;
248
            }
249
        } elseif ($num == 0 || $num == '') {
250
            return $this->_sep . $this->_digits[0];
251
        }
252
 
253
        $h = $t = $d = 0;
254
 
255
        switch(strlen($num)) {
256
        case 3:
257
            $h = (int)substr($num, -3, 1);
258
 
259
        case 2:
260
            $t = (int)substr($num, -2, 1);
261
 
262
        case 1:
263
            $d = (int)substr($num, -1, 1);
264
            break;
265
 
266
        case 0:
267
            return;
268
            break;
269
        }
270
 
271
        if ($h) {
272
            $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'száz';
273
        }
274
 
275
        // ten, twenty etc.
276
        switch ($t) {
277
        case 9:
278
        case 5:
279
            $ret .= $this->_sep . $this->_digits[$t] . 'ven';
280
            break;
281
        case 8:
282
        case 6:
283
            $ret .= $this->_sep . $this->_digits[$t] . 'van';
284
            break;
285
        case 7:
286
            $ret .= $this->_sep . 'hetven';
287
            break;
288
        case 3:
289
            $ret .= $this->_sep . 'harminc';
290
            break;
291
        case 4:
292
            $ret .= $this->_sep . 'negyven';
293
            break;
294
        case 2:
295
            switch ($d) {
296
            case 0:
297
                $ret .= $this->_sep . 'húsz';
298
                break;
299
            case 1:
300
            case 2:
301
            case 3:
302
            case 4:
303
            case 5:
304
            case 6:
305
            case 7:
306
            case 8:
307
            case 9:
308
                $ret .= $this->_sep . 'húszon';
309
                break;
310
            }
311
            break;
312
        case 1:
313
            switch ($d) {
314
            case 0:
315
                $ret .= $this->_sep . 'tíz';
316
                break;
317
            case 1:
318
            case 2:
319
            case 3:
320
            case 4:
321
            case 5:
322
            case 6:
323
            case 7:
324
            case 8:
325
            case 9:
326
                $ret .= $this->_sep . 'tizen';
327
                break;
328
            }
329
            break;
330
        }
331
 
332
        if ($d > 0) { // add digits only in <0> and <1,inf)
333
            $ret .= $this->_sep . $this->_digits[$d];
334
        }
335
 
336
        if ($power > 0) {
337
            if (isset($this->_exponent[$power])) {
338
                $lev = $this->_exponent[$power];
339
            }
340
 
341
            if (!isset($lev) || !is_array($lev)) {
342
                return null;
343
            }
344
 
345
            $ret .= $this->_sep . $lev[0];
346
        }
347
 
348
        if ($powsuffix != '') {
349
            $ret .= $this->_sep . $powsuffix;
350
        }
351
 
352
        return $ret;
353
    }
354
    // }}}
355
    // {{{ toCurrencyWords()
356
 
357
    /**
358
     * Converts a currency value to its word representation
359
     * (with monetary units) in English language
360
     *
361
     * @param integer $int_curr         An international currency symbol
362
     *                                  as defined by the ISO 4217 standard (three characters)
363
     * @param integer $decimal          A money total amount without fraction part (e.g. amount of dollars)
364
     * @param integer $fraction         Fractional part of the money amount (e.g. amount of cents)
365
     *                                  Optional. Defaults to false.
366
     * @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
367
     *                                  Optional. Defaults to true.
368
     *
369
     * @return string  The corresponding word representation for the currency
370
     *
371
     * @access public
372
     * @author Piotr Klaban <makler@man.torun.pl>
373
     * @since  Numbers_Words 0.4
374
     */
375
    function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
376
    {
377
        $int_curr = strtoupper($int_curr);
378
        if (!isset($this->_currency_names[$int_curr])) {
379
            $int_curr = $this->def_currency;
380
        }
381
        $curr_names = $this->_currency_names[$int_curr];
382
 
383
        $ret = trim($this->toWords($decimal));
384
        $lev = ($decimal == 1) ? 0 : 1;
385
        if ($lev > 0) {
386
            if (count($curr_names[0]) > 1) {
387
                $ret .= $this->_sep . $curr_names[0][$lev];
388
            } else {
389
                $ret .= $this->_sep . $curr_names[0][0] . 's';
390
            }
391
        } else {
392
            $ret .= $this->_sep . $curr_names[0][0];
393
        }
394
 
395
        if ($fraction !== false) {
396
            if ($convert_fraction) {
397
                $ret .= $this->_sep . trim($this->toWords($fraction));
398
            } else {
399
                $ret .= $this->_sep . $fraction;
400
            }
401
            $lev = ($fraction == 1) ? 0 : 1;
402
            if ($lev > 0) {
403
                if (count($curr_names[1]) > 1) {
404
                    $ret .= $this->_sep . $curr_names[1][$lev];
405
                } else {
406
                    $ret .= $this->_sep . $curr_names[1][0] . 's';
407
                }
408
            } else {
409
                $ret .= $this->_sep . $curr_names[1][0];
410
            }
411
        }
412
        return $ret;
413
    }
414
    // }}}
415
 
416
}
417
 
418
?>