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.en_GB.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 British English.
27
 *
28
 * @author Piotr Klaban
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 British English.
39
 *
40
 * @category Numbers
41
 * @package  Numbers_Words
42
 * @author   Piotr Klaban <makler@man.torun.pl>
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_en_GB extends Numbers_Words
47
{
48
 
49
    // {{{ properties
50
 
51
    /**
52
     * Locale name
53
     * @var string
54
     * @access public
55
     */
56
    var $locale = 'en_GB';
57
 
58
    /**
59
     * Language name in English
60
     * @var string
61
     * @access public
62
     */
63
    var $lang = 'British English';
64
 
65
    /**
66
     * Native language name
67
     * @var string
68
     * @access public
69
     */
70
    var $lang_native = 'British English';
71
 
72
    /**
73
     * The word for the minus sign
74
     * @var string
75
     * @access private
76
     */
77
    var $_minus = 'minus'; // minus sign
78
 
79
    /**
80
     * The sufixes for exponents (singular and plural)
81
     * Names partly based on:
82
     * http://www.users.dircon.co.uk/~shaunf/shaun/numbers/millions.htm
83
     * @var array
84
     * @access private
85
     */
86
    var $_exponent = array(
87
 
88
        3 => array('thousand'),
89
        6 => array('million'),
90
       12 => array('billion'),
91
       18 => array('trillion'),
92
       24 => array('quadrillion'),
93
       30 => array('quintillion'),
94
       36 => array('sextillion'),
95
       42 => array('septillion'),
96
       48 => array('octillion'),
97
       54 => array('nonillion'),
98
       60 => array('decillion'),
99
       66 => array('undecillion'),
100
       72 => array('duodecillion'),
101
       78 => array('tredecillion'),
102
       84 => array('quattuordecillion'),
103
       90 => array('quindecillion'),
104
       96 => array('sexdecillion'),
105
      102 => array('septendecillion'),
106
      108 => array('octodecillion'),
107
      114 => array('novemdecillion'),
108
      120 => array('vigintillion'),
109
      192 => array('duotrigintillion'),
110
      600 => array('centillion')
111
        );
112
 
113
    /**
114
     * The array containing the digits (indexed by the digits themselves).
115
     * @var array
116
     * @access private
117
     */
118
    var $_digits = array(
119
 
120
        'five', 'six', 'seven', 'eight', 'nine'
121
    );
122
 
123
    /**
124
     * The word separator
125
     * @var string
126
     * @access private
127
     */
128
    var $_sep = ' ';
129
 
130
    /**
131
     * The currency names (based on the below links,
132
     * informations from central bank websites and on encyclopedias)
133
     *
134
     * @var array
135
     * @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
136
     * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
137
     * @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
138
     * @access private
139
     */
140
    var $_currency_names = array(
141
      'ALL' => array(array('lek'), array('qindarka')),
142
      'AUD' => array(array('Australian dollar'), array('cent')),
143
      'BAM' => array(array('convertible marka'), array('fenig')),
144
      'BGN' => array(array('lev'), array('stotinka')),
145
      'BRL' => array(array('real'), array('centavos')),
146
      'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
147
      'CAD' => array(array('Canadian dollar'), array('cent')),
148
      'CHF' => array(array('Swiss franc'), array('rapp')),
149
      'CYP' => array(array('Cypriot pound'), array('cent')),
150
      'CZK' => array(array('Czech koruna'), array('halerz')),
151
      'DKK' => array(array('Danish krone'), array('ore')),
152
      'EEK' => array(array('kroon'), array('senti')),
153
      'EUR' => array(array('euro'), array('euro-cent')),
154
      'GBP' => array(array('pound', 'pounds'), array('pence', 'pence')),
155
      'HKD' => array(array('Hong Kong dollar'), array('cent')),
156
      'HRK' => array(array('Croatian kuna'), array('lipa')),
157
      'HUF' => array(array('forint'), array('filler')),
158
      'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
159
      'ISK' => array(array('Icelandic króna'), array('aurar')),
160
      'JPY' => array(array('yen'), array('sen')),
161
      'LTL' => array(array('litas'), array('cent')),
162
      'LVL' => array(array('lat'), array('sentim')),
163
      'MKD' => array(array('Macedonian dinar'), array('deni')),
164
      'MTL' => array(array('Maltese lira'), array('centym')),
165
      'NOK' => array(array('Norwegian krone'), array('oere')),
166
      'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
167
      'ROL' => array(array('Romanian leu'), array('bani')),
168
      'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
169
      'SEK' => array(array('Swedish krona'), array('oere')),
170
      'SIT' => array(array('Tolar'), array('stotinia')),
171
      'SKK' => array(array('Slovak koruna'), array()),
172
      'TRL' => array(array('lira'), array('kuruþ')),
173
      'UAH' => array(array('hryvna'), array('cent')),
174
      'USD' => array(array('dollar'), array('cent')),
175
      'YUM' => array(array('dinars'), array('para')),
176
      'ZAR' => array(array('rand'), array('cent'))
177
    );
178
 
179
    /**
180
     * The default currency name
181
     * @var string
182
     * @access public
183
     */
184
    var $def_currency = 'GBP'; // English pound
185
 
186
    // }}}
187
    // {{{ toWords()
188
 
189
    /**
190
     * Converts a number to its word representation
191
     * in British English language
192
     *
193
     * @param integer $num       An integer between -infinity and infinity inclusive :)
194
     *                           that need to be converted to words
195
     * @param integer $power     The power of ten for the rest of the number to the right.
196
     *                           Optional, defaults to 0.
197
     * @param integer $powsuffix The power name to be added to the end of the return string.
198
     *                            Used internally. Optional, defaults to ''.
199
     *
200
     * @return string  The corresponding word representation
201
     *
202
     * @access public
203
     * @author Piotr Klaban <makler@man.torun.pl>
204
     * @since  PHP 4.2.3
205
     */
206
    function toWords($num, $power = 0, $powsuffix = '')
207
    {
208
        $ret = '';
209
 
210
        // add a minus sign
211
        if (substr($num, 0, 1) == '-') {
212
            $ret = $this->_sep . $this->_minus;
213
            $num = substr($num, 1);
214
        }
215
 
216
        // strip excessive zero signs and spaces
217
        $num = trim($num);
218
        $num = preg_replace('/^0+/', '', $num);
219
 
220
        if (strlen($num) > 3) {
221
            $maxp = strlen($num)-1;
222
            $curp = $maxp;
223
            for ($p = $maxp; $p > 0; --$p) { // power
224
 
225
                // check for highest power
226
                if (isset($this->_exponent[$p])) {
227
                    // send substr from $curp to $p
228
                    $snum = substr($num, $maxp - $curp, $curp - $p + 1);
229
                    $snum = preg_replace('/^0+/', '', $snum);
230
                    if ($snum !== '') {
231
                        $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
232
                        if ($powsuffix != '') {
233
                            $cursuffix .= $this->_sep . $powsuffix;
234
                        }
235
 
236
                        $ret .= $this->toWords($snum, $p, $cursuffix);
237
                    }
238
                    $curp = $p - 1;
239
                    continue;
240
                }
241
            }
242
            $num = substr($num, $maxp - $curp, $curp - $p + 1);
243
            if ($num == 0) {
244
                return $ret;
245
            }
246
        } elseif ($num == 0 || $num == '') {
247
            return $this->_sep . $this->_digits[0];
248
        }
249
 
250
        $h = $t = $d = 0;
251
 
252
        switch(strlen($num)) {
253
        case 3:
254
            $h = (int)substr($num, -3, 1);
255
 
256
        case 2:
257
            $t = (int)substr($num, -2, 1);
258
 
259
        case 1:
260
            $d = (int)substr($num, -1, 1);
261
            break;
262
 
263
        case 0:
264
            return;
265
            break;
266
        }
267
 
268
        if ($h) {
269
            $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundred';
270
 
271
            // in English only - add ' and' for [1-9]01..[1-9]99
272
            // (also for 1001..1099, 10001..10099 but it is harder)
273
            // for now it is switched off, maybe some language purists
274
            // can force me to enable it, or to remove it completely
275
            // if (($t + $d) > 0)
276
            //   $ret .= $this->_sep . 'and';
277
        }
278
 
279
        // ten, twenty etc.
280
        switch ($t) {
281
        case 9:
282
        case 7:
283
        case 6:
284
            $ret .= $this->_sep . $this->_digits[$t] . 'ty';
285
            break;
286
 
287
        case 8:
288
            $ret .= $this->_sep . 'eighty';
289
            break;
290
 
291
        case 5:
292
            $ret .= $this->_sep . 'fifty';
293
            break;
294
 
295
        case 4:
296
            $ret .= $this->_sep . 'forty';
297
            break;
298
 
299
        case 3:
300
            $ret .= $this->_sep . 'thirty';
301
            break;
302
 
303
        case 2:
304
            $ret .= $this->_sep . 'twenty';
305
            break;
306
 
307
        case 1:
308
            switch ($d) {
309
            case 0:
310
                $ret .= $this->_sep . 'ten';
311
                break;
312
 
313
            case 1:
314
                $ret .= $this->_sep . 'eleven';
315
                break;
316
 
317
            case 2:
318
                $ret .= $this->_sep . 'twelve';
319
                break;
320
 
321
            case 3:
322
                $ret .= $this->_sep . 'thirteen';
323
                break;
324
 
325
            case 4:
326
            case 6:
327
            case 7:
328
            case 9:
329
                $ret .= $this->_sep . $this->_digits[$d] . 'teen';
330
                break;
331
 
332
            case 5:
333
                $ret .= $this->_sep . 'fifteen';
334
                break;
335
 
336
            case 8:
337
                $ret .= $this->_sep . 'eighteen';
338
                break;
339
            }
340
            break;
341
        }
342
 
343
        if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
344
            // add minus sign between [2-9] and digit
345
            if ($t > 1) {
346
                $ret .= '-' . $this->_digits[$d];
347
            } else {
348
                $ret .= $this->_sep . $this->_digits[$d];
349
            }
350
        }
351
 
352
        if ($power > 0) {
353
            if (isset($this->_exponent[$power])) {
354
                $lev = $this->_exponent[$power];
355
            }
356
 
357
            if (!isset($lev) || !is_array($lev)) {
358
                return null;
359
            }
360
 
361
            $ret .= $this->_sep . $lev[0];
362
        }
363
 
364
        if ($powsuffix != '') {
365
            $ret .= $this->_sep . $powsuffix;
366
        }
367
 
368
        return $ret;
369
    }
370
    // }}}
371
    // {{{ toCurrencyWords()
372
 
373
    /**
374
     * Converts a currency value to its word representation
375
     * (with monetary units) in English language
376
     *
377
     * @param integer $int_curr         An international currency symbol
378
     *                                  as defined by the ISO 4217 standard (three characters)
379
     * @param integer $decimal          A money total amount without fraction part (e.g. amount of dollars)
380
     * @param integer $fraction         Fractional part of the money amount (e.g. amount of cents)
381
     *                                  Optional. Defaults to false.
382
     * @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
383
     *                                  Optional. Defaults to true.
384
     *
385
     * @return string  The corresponding word representation for the currency
386
     *
387
     * @access public
388
     * @author Piotr Klaban <makler@man.torun.pl>
389
     * @since  Numbers_Words 0.13.1
390
     */
391
    function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
392
    {
393
        $int_curr = strtoupper($int_curr);
394
        if (!isset($this->_currency_names[$int_curr])) {
395
            $int_curr = $this->def_currency;
396
        }
397
        $curr_names = $this->_currency_names[$int_curr];
398
 
399
        $ret = trim($this->toWords($decimal));
400
        $lev = ($decimal == 1) ? 0 : 1;
401
        if ($lev > 0) {
402
            if (count($curr_names[0]) > 1) {
403
                $ret .= $this->_sep . $curr_names[0][$lev];
404
            } else {
405
                $ret .= $this->_sep . $curr_names[0][0] . 's';
406
            }
407
        } else {
408
            $ret .= $this->_sep . $curr_names[0][0];
409
        }
410
 
411
        if ($fraction !== false) {
412
            if ($convert_fraction) {
413
                $ret .= $this->_sep . trim($this->toWords($fraction));
414
            } else {
415
                $ret .= $this->_sep . $fraction;
416
            }
417
            $lev = ($fraction == 1) ? 0 : 1;
418
            if ($lev > 0) {
419
                if (count($curr_names[1]) > 1) {
420
                    $ret .= $this->_sep . $curr_names[1][$lev];
421
                } else {
422
                    $ret .= $this->_sep . $curr_names[1][0] . 's';
423
                }
424
            } else {
425
                $ret .= $this->_sep . $curr_names[1][0];
426
            }
427
        }
428
        return $ret;
429
    }
430
    // }}}
431
 
432
 
433
}
434
 
435
?>