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   Laurynas Butkus <lauris@night.lt>
20
 * @license  PHP 3.0 http://www.php.net/license/3_0.txt
21
 * @version  CVS: $Id: lang.lt.php 269651 2008-11-25 03:48:32Z clockwerx $
22
 * @link     http://pear.php.net/package/Numbers_Words
23
 */
24
 
25
/**
26
 * Class for translating numbers into Lithuanian.
27
 *
28
 * @author Laurynas Butkus
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 Lithuanian.
39
 *
40
 * @category Numbers
41
 * @package  Numbers_Words
42
 * @author   Laurynas Butkus <lauris@night.lt>
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_lt extends Numbers_Words
47
{
48
 
49
    // {{{ properties
50
 
51
    /**
52
     * Locale name
53
     * @var string
54
     * @access public
55
     */
56
    var $locale = 'lt';
57
 
58
    /**
59
     * Language name in English
60
     * @var string
61
     * @access public
62
     */
63
    var $lang = 'Lithuanian';
64
 
65
    /**
66
     * Native language name
67
     * @var string
68
     * @access public
69
     */
70
    var $lang_native = 'lietuviðkai';
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
     * @var array
82
     * @access private
83
     */
84
    var $_exponent = array(
85
 
86
        3 => array('tûkstantis','tûkstanèiai','tûkstanèiø'),
87
        6 => array('milijonas','milijonai','milijonø'),
88
        9 => array('bilijonas','bilijonai','bilijonø'),
89
       12 => array('trilijonas','trilijonai','trilijonø'),
90
       15 => array('kvadrilijonas','kvadrilijonai','kvadrilijonø'),
91
       18 => array('kvintilijonas','kvintilijonai','kvintilijonø')
92
        );
93
 
94
    /**
95
     * The array containing the digits (indexed by the digits themselves).
96
     * @var array
97
     * @access private
98
     */
99
    var $_digits = array(
100
 
101
        'penki', 'ðeði', 'septyni', 'aðtuoni', 'devyni'
102
    );
103
 
104
    /**
105
     * The word separator
106
     * @var string
107
     * @access private
108
     */
109
    var $_sep = ' ';
110
 
111
    /**
112
     * The default currency name
113
     * @var string
114
     * @access public
115
     */
116
    var $def_currency = 'LTL';
117
 
118
    // }}}
119
    // {{{ toWords()
120
 
121
    /**
122
     * Converts a number to its word representation
123
     * in Lithuanian language
124
     *
125
     * @param integer $num       An integer between -infinity and infinity inclusive :)
126
     *                           that need to be converted to words
127
     * @param integer $power     The power of ten for the rest of the number to the right.
128
     *                           Optional, defaults to 0.
129
     * @param integer $powsuffix The power name to be added to the end of the return string.
130
     *                            Used internally. Optional, defaults to ''.
131
     *
132
     * @return string  The corresponding word representation
133
     *
134
     * @access public
135
     * @author Laurynas Butkus <lauris@night.lt>
136
     * @since  PHP 4.2.3
137
     */
138
    function toWords($num, $power = 0, $powsuffix = '')
139
    {
140
        $ret = '';
141
 
142
        // add a minus sign
143
        if (substr($num, 0, 1) == '-') {
144
            $ret = $this->_sep . $this->_minus;
145
            $num = substr($num, 1);
146
        }
147
 
148
        // strip excessive zero signs and spaces
149
        $num = trim($num);
150
        $num = preg_replace('/^0+/', '', $num);
151
 
152
        if (strlen($num) > 3) {
153
            $maxp = strlen($num)-1;
154
            $curp = $maxp;
155
            for ($p = $maxp; $p > 0; --$p) { // power
156
 
157
                // check for highest power
158
                if (isset($this->_exponent[$p])) {
159
                    // send substr from $curp to $p
160
                    $snum = substr($num, $maxp - $curp, $curp - $p + 1);
161
                    $snum = preg_replace('/^0+/', '', $snum);
162
                    if ($snum !== '') {
163
                        $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
164
                        if ($powsuffix != '') {
165
                            $cursuffix .= $this->_sep . $powsuffix;
166
                        }
167
 
168
                        $ret .= $this->toWords($snum, $p, $cursuffix);
169
                    }
170
                    $curp = $p - 1;
171
                    continue;
172
                }
173
            }
174
            $num = substr($num, $maxp - $curp, $curp - $p + 1);
175
            if ($num == 0) {
176
                return $ret;
177
            }
178
        } elseif ($num == 0 || $num == '') {
179
            return $this->_sep . $this->_digits[0];
180
        }
181
 
182
        $h = $t = $d = 0;
183
 
184
        switch(strlen($num)) {
185
        case 3:
186
            $h = (int)substr($num, -3, 1);
187
 
188
        case 2:
189
            $t = (int)substr($num, -2, 1);
190
 
191
        case 1:
192
            $d = (int)substr($num, -1, 1);
193
            break;
194
 
195
        case 0:
196
            return;
197
            break;
198
        }
199
 
200
        if ( $h > 1 ) {
201
            $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'ðimtai';
202
        } elseif ( $h ) {
203
            $ret .= $this->_sep . 'ðimtas';
204
        }
205
 
206
        // ten, twenty etc.
207
        switch ($t) {
208
        case 9:
209
            $ret .= $this->_sep . 'devyniasdeðimt';
210
            break;
211
 
212
        case 8:
213
            $ret .= $this->_sep . 'aðtuoniasdeðimt';
214
            break;
215
 
216
        case 7:
217
            $ret .= $this->_sep . 'septyniasdeðimt';
218
            break;
219
 
220
        case 6:
221
            $ret .= $this->_sep . 'ðeðiasdeðimt';
222
            break;
223
 
224
        case 5:
225
            $ret .= $this->_sep . 'penkiasdeðimt';
226
            break;
227
 
228
        case 4:
229
            $ret .= $this->_sep . 'keturiasdeðimt';
230
            break;
231
 
232
        case 3:
233
            $ret .= $this->_sep . 'trisdeðimt';
234
            break;
235
 
236
        case 2:
237
            $ret .= $this->_sep . 'dvideðimt';
238
            break;
239
 
240
        case 1:
241
            switch ($d) {
242
            case 0:
243
                $ret .= $this->_sep . 'deðimt';
244
                break;
245
 
246
            case 1:
247
                $ret .= $this->_sep . 'vienuolika';
248
                break;
249
 
250
            case 2:
251
                $ret .= $this->_sep . 'dvylika';
252
                break;
253
 
254
            case 3:
255
                $ret .= $this->_sep . 'trylika';
256
                break;
257
 
258
            case 4:
259
                $ret .= $this->_sep . 'keturiolika';
260
                break;
261
 
262
            case 5:
263
                $ret .= $this->_sep . 'penkiolika';
264
                break;
265
 
266
            case 6:
267
                $ret .= $this->_sep . 'ðeðiolika';
268
                break;
269
 
270
            case 7:
271
                $ret .= $this->_sep . 'septyniolika';
272
                break;
273
 
274
            case 8:
275
                $ret .= $this->_sep . 'aðtuoniolika';
276
                break;
277
 
278
            case 9:
279
                $ret .= $this->_sep . 'devyniolika';
280
                break;
281
 
282
            }
283
            break;
284
        }
285
 
286
        // add digits only in <0>,<1,9> and <21,inf>
287
        if ($t != 1 && $d > 0) {
288
            if ( $d > 1 || !$power || $t ) {
289
                $ret .= $this->_sep . $this->_digits[$d];
290
            }
291
        }
292
 
293
        if ($power > 0) {
294
            if (isset($this->_exponent[$power])) {
295
                $lev = $this->_exponent[$power];
296
            }
297
 
298
            if (!isset($lev) || !is_array($lev)) {
299
                return null;
300
            }
301
 
302
            //echo " $t $d  <br>";
303
 
304
            if ($t == 1 || ($t > 0 && $d == 0 )) {
305
                $ret .= $this->_sep . $lev[2];
306
            } elseif ( $d > 1 ) {
307
                $ret .= $this->_sep . $lev[1];
308
            } else {
309
                $ret .= $this->_sep . $lev[0];
310
            }
311
        }
312
 
313
        if ($powsuffix != '') {
314
            $ret .= $this->_sep . $powsuffix;
315
        }
316
 
317
        return $ret;
318
    }
319
    // }}}
320
 
321
}
322
 
323
?>