| 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 Xavier Noguer <xnoguer.php@gmail.com>
|
|
|
20 |
* @author Martin Marrese <mmare@mecon.gov.ar>
|
|
|
21 |
* @license PHP 3.0 http://www.php.net/license/3_0.txt
|
|
|
22 |
* @version CVS: $Id: lang.es_AR.php 269823 2008-11-25 13:47:38Z clockwerx $
|
|
|
23 |
* @link http://pear.php.net/package/Numbers_Words
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Class for translating numbers into Argentinian Spanish.
|
|
|
28 |
*
|
|
|
29 |
* @author Martin Marrese
|
|
|
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 Argentinian Spanish.
|
|
|
40 |
* It supports up to decallones (10^6).
|
|
|
41 |
* It doesn't support spanish tonic accents (acentos).
|
|
|
42 |
*
|
|
|
43 |
* @category Numbers
|
|
|
44 |
* @package Numbers_Words
|
|
|
45 |
* @author Xavier Noguer <xnoguer.php@gmail.com>
|
|
|
46 |
* @author Martin Marrese <mmare@mecon.gov.ar>
|
|
|
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_es_AR extends Numbers_Words
|
|
|
51 |
{
|
|
|
52 |
// {{{ properties
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Locale name
|
|
|
56 |
* @var string
|
|
|
57 |
* @access public
|
|
|
58 |
*/
|
|
|
59 |
var $locale = 'es_AR';
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Language name in English
|
|
|
63 |
* @var string
|
|
|
64 |
* @access public
|
|
|
65 |
*/
|
|
|
66 |
var $lang = 'Spanish';
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Native language name
|
|
|
70 |
* @var string
|
|
|
71 |
* @access public
|
|
|
72 |
*/
|
|
|
73 |
var $lang_native = 'Español';
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* The word for the minus sign
|
|
|
77 |
* @var string
|
|
|
78 |
* @access private
|
|
|
79 |
*/
|
|
|
80 |
var $_minus = 'menos';
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* The sufixes for exponents (singular and plural)
|
|
|
84 |
* @var array
|
|
|
85 |
* @access private
|
|
|
86 |
*/
|
|
|
87 |
var $_exponent = array(
|
|
|
88 |
|
|
|
89 |
3 => array('mil','mil'),
|
|
|
90 |
6 => array('millón','millones'),
|
|
|
91 |
12 => array('billón','billones'),
|
|
|
92 |
18 => array('trilón','trillones'),
|
|
|
93 |
24 => array('cuatrillón','cuatrillones'),
|
|
|
94 |
30 => array('quintillón','quintillones'),
|
|
|
95 |
36 => array('sextillón','sextillones'),
|
|
|
96 |
42 => array('septillón','septillones'),
|
|
|
97 |
48 => array('octallón','octallones'),
|
|
|
98 |
54 => array('nonallón','nonallones'),
|
|
|
99 |
60 => array('decallón','decallones'),
|
|
|
100 |
);
|
|
|
101 |
/**
|
|
|
102 |
* The array containing the digits (indexed by the digits themselves).
|
|
|
103 |
* @var array
|
|
|
104 |
* @access private
|
|
|
105 |
*/
|
|
|
106 |
var $_digits = array(
|
|
|
107 |
|
|
|
108 |
'cinco', 'seis', 'siete', 'ocho', 'nueve'
|
|
|
109 |
);
|
|
|
110 |
/**
|
|
|
111 |
* The word separator
|
|
|
112 |
* @var string
|
|
|
113 |
* @access private
|
|
|
114 |
*/
|
|
|
115 |
var $_sep = ' ';
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* The currency names (based on the below links,
|
|
|
119 |
* informations from central bank websites and on encyclopedias)
|
|
|
120 |
*
|
|
|
121 |
* @var array
|
|
|
122 |
* @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
|
|
|
123 |
* @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
|
|
|
124 |
* @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
|
|
|
125 |
* @access private
|
|
|
126 |
*/
|
|
|
127 |
var $_currency_names = array(
|
|
|
128 |
'ALL' => array(array('lek'), array('qindarka')),
|
|
|
129 |
'AUD' => array(array('Australian dollar'), array('cent')),
|
|
|
130 |
'ARS' => array(array('Peso'), array ('centavo')),
|
|
|
131 |
'BAM' => array(array('convertible marka'), array('fenig')),
|
|
|
132 |
'BGN' => array(array('lev'), array('stotinka')),
|
|
|
133 |
'BRL' => array(array('real'), array('centavos')),
|
|
|
134 |
'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
|
|
|
135 |
'CAD' => array(array('Canadian dollar'), array('cent')),
|
|
|
136 |
'CHF' => array(array('Swiss franc'), array('rapp')),
|
|
|
137 |
'CYP' => array(array('Cypriot pound'), array('cent')),
|
|
|
138 |
'CZK' => array(array('Czech koruna'), array('halerz')),
|
|
|
139 |
'DKK' => array(array('Danish krone'), array('ore')),
|
|
|
140 |
'EEK' => array(array('kroon'), array('senti')),
|
|
|
141 |
'EUR' => array(array('euro'), array('euro-cent')),
|
|
|
142 |
'GBP' => array(array('pound', 'pounds'), array('pence')),
|
|
|
143 |
'HKD' => array(array('Hong Kong dollar'), array('cent')),
|
|
|
144 |
'HRK' => array(array('Croatian kuna'), array('lipa')),
|
|
|
145 |
'HUF' => array(array('forint'), array('filler')),
|
|
|
146 |
'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
|
|
|
147 |
'ISK' => array(array('Icelandic króna'), array('aurar')),
|
|
|
148 |
'JPY' => array(array('yen'), array('sen')),
|
|
|
149 |
'LTL' => array(array('litas'), array('cent')),
|
|
|
150 |
'LVL' => array(array('lat'), array('sentim')),
|
|
|
151 |
'MKD' => array(array('Macedonian dinar'), array('deni')),
|
|
|
152 |
'MTL' => array(array('Maltese lira'), array('centym')),
|
|
|
153 |
'NOK' => array(array('Norwegian krone'), array('oere')),
|
|
|
154 |
'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
|
|
|
155 |
'ROL' => array(array('Romanian leu'), array('bani')),
|
|
|
156 |
'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
|
|
|
157 |
'SEK' => array(array('Swedish krona'), array('oere')),
|
|
|
158 |
'SIT' => array(array('Tolar'), array('stotinia')),
|
|
|
159 |
'SKK' => array(array('Slovak koruna'), array()),
|
|
|
160 |
'TRL' => array(array('lira'), array('kuruþ')),
|
|
|
161 |
'UAH' => array(array('hryvna'), array('cent')),
|
|
|
162 |
'USD' => array(array('dollar'), array('cent')),
|
|
|
163 |
'YUM' => array(array('dinars'), array('para')),
|
|
|
164 |
'ZAR' => array(array('rand'), array('cent'))
|
|
|
165 |
);
|
|
|
166 |
|
|
|
167 |
/**
|
|
|
168 |
* The default currency name
|
|
|
169 |
* @var string
|
|
|
170 |
* @access public
|
|
|
171 |
*/
|
|
|
172 |
var $def_currency = 'ARS'; // Argentinian Peso
|
|
|
173 |
|
|
|
174 |
// }}}
|
|
|
175 |
// {{{ toWords()
|
|
|
176 |
/**
|
|
|
177 |
* Converts a number to its word representation
|
|
|
178 |
* in Argentinian Spanish.
|
|
|
179 |
*
|
|
|
180 |
* @param float $num An float between -infinity and infinity inclusive :)
|
|
|
181 |
* that should be converted to a words representation
|
|
|
182 |
* @param integer $power The power of ten for the rest of the number to the right.
|
|
|
183 |
* For example toWords(12,3) should give "doce mil".
|
|
|
184 |
* Optional, defaults to 0.
|
|
|
185 |
*
|
|
|
186 |
* @return string The corresponding word representation
|
|
|
187 |
*
|
|
|
188 |
* @access private
|
|
|
189 |
* @author Martin Marrese
|
|
|
190 |
*/
|
|
|
191 |
function toWords($num, $power = 0)
|
|
|
192 |
{
|
|
|
193 |
// The return string;
|
|
|
194 |
$ret = '';
|
|
|
195 |
|
|
|
196 |
// add a the word for the minus sign if necessary
|
|
|
197 |
if (substr($num, 0, 1) == '-') {
|
|
|
198 |
$ret = $this->_sep . $this->_minus;
|
|
|
199 |
$num = substr($num, 1);
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
// strip excessive zero signs
|
|
|
204 |
$num = preg_replace('/^0+/', '', $num);
|
|
|
205 |
|
|
|
206 |
$num_tmp = split('\.', $num);
|
|
|
207 |
|
|
|
208 |
$num = $num_tmp[0];
|
|
|
209 |
$dec = (@$num_tmp[1]) ? $num_tmp[1] : '';
|
|
|
210 |
|
|
|
211 |
if (strlen($num) > 6) {
|
|
|
212 |
$current_power = 6;
|
|
|
213 |
// check for highest power
|
|
|
214 |
if (isset($this->_exponent[$power])) {
|
|
|
215 |
// convert the number above the first 6 digits
|
|
|
216 |
// with it's corresponding $power.
|
|
|
217 |
$snum = substr($num, 0, -6);
|
|
|
218 |
$snum = preg_replace('/^0+/', '', $snum);
|
|
|
219 |
if ($snum !== '') {
|
|
|
220 |
$ret .= $this->toWords($snum, $power + 6);
|
|
|
221 |
}
|
|
|
222 |
}
|
|
|
223 |
$num = substr($num, -6);
|
|
|
224 |
if ($num == 0) {
|
|
|
225 |
return $ret;
|
|
|
226 |
}
|
|
|
227 |
} elseif ($num == 0 || $num == '') {
|
|
|
228 |
return(' '.$this->_digits[0]);
|
|
|
229 |
$current_power = strlen($num);
|
|
|
230 |
} else {
|
|
|
231 |
$current_power = strlen($num);
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
// See if we need "thousands"
|
|
|
235 |
$thousands = floor($num / 1000);
|
|
|
236 |
if ($thousands == 1) {
|
|
|
237 |
$ret .= $this->_sep . 'mil';
|
|
|
238 |
} elseif ($thousands > 1) {
|
|
|
239 |
$ret .= $this->toWords($thousands, 3);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
// values for digits, tens and hundreds
|
|
|
243 |
$h = floor(($num / 100) % 10);
|
|
|
244 |
$t = floor(($num / 10) % 10);
|
|
|
245 |
$d = floor($num % 10);
|
|
|
246 |
|
|
|
247 |
// cientos: doscientos, trescientos, etc...
|
|
|
248 |
switch ($h) {
|
|
|
249 |
case 1:
|
|
|
250 |
if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
|
|
|
251 |
$ret .= $this->_sep . 'cien';
|
|
|
252 |
} else {
|
|
|
253 |
$ret .= $this->_sep . 'ciento';
|
|
|
254 |
}
|
|
|
255 |
break;
|
|
|
256 |
case 2:
|
|
|
257 |
case 3:
|
|
|
258 |
case 4:
|
|
|
259 |
case 6:
|
|
|
260 |
case 8:
|
|
|
261 |
$ret .= $this->_sep . $this->_digits[$h] . 'cientos';
|
|
|
262 |
break;
|
|
|
263 |
case 5:
|
|
|
264 |
$ret .= $this->_sep . 'quinientos';
|
|
|
265 |
break;
|
|
|
266 |
case 7:
|
|
|
267 |
$ret .= $this->_sep . 'setecientos';
|
|
|
268 |
break;
|
|
|
269 |
case 9:
|
|
|
270 |
$ret .= $this->_sep . 'novecientos';
|
|
|
271 |
break;
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
// decenas: veinte, treinta, etc...
|
|
|
275 |
switch ($t) {
|
|
|
276 |
case 9:
|
|
|
277 |
$ret .= $this->_sep . 'noventa';
|
|
|
278 |
break;
|
|
|
279 |
|
|
|
280 |
case 8:
|
|
|
281 |
$ret .= $this->_sep . 'ochenta';
|
|
|
282 |
break;
|
|
|
283 |
|
|
|
284 |
case 7:
|
|
|
285 |
$ret .= $this->_sep . 'setenta';
|
|
|
286 |
break;
|
|
|
287 |
|
|
|
288 |
case 6:
|
|
|
289 |
$ret .= $this->_sep . 'sesenta';
|
|
|
290 |
break;
|
|
|
291 |
|
|
|
292 |
case 5:
|
|
|
293 |
$ret .= $this->_sep . 'cincuenta';
|
|
|
294 |
break;
|
|
|
295 |
|
|
|
296 |
case 4:
|
|
|
297 |
$ret .= $this->_sep . 'cuarenta';
|
|
|
298 |
break;
|
|
|
299 |
|
|
|
300 |
case 3:
|
|
|
301 |
$ret .= $this->_sep . 'treinta';
|
|
|
302 |
break;
|
|
|
303 |
|
|
|
304 |
case 2:
|
|
|
305 |
if ($d == 0) {
|
|
|
306 |
$ret .= $this->_sep . 'veinte';
|
|
|
307 |
} else {
|
|
|
308 |
if (($power > 0) and ($d == 1)) {
|
|
|
309 |
$ret .= $this->_sep . 'veintiún';
|
|
|
310 |
} else {
|
|
|
311 |
$ret .= $this->_sep . 'veinti' . $this->_digits[$d];
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
break;
|
|
|
315 |
|
|
|
316 |
case 1:
|
|
|
317 |
switch ($d) {
|
|
|
318 |
case 0:
|
|
|
319 |
$ret .= $this->_sep . 'diez';
|
|
|
320 |
break;
|
|
|
321 |
|
|
|
322 |
case 1:
|
|
|
323 |
$ret .= $this->_sep . 'once';
|
|
|
324 |
break;
|
|
|
325 |
|
|
|
326 |
case 2:
|
|
|
327 |
$ret .= $this->_sep . 'doce';
|
|
|
328 |
break;
|
|
|
329 |
|
|
|
330 |
case 3:
|
|
|
331 |
$ret .= $this->_sep . 'trece';
|
|
|
332 |
break;
|
|
|
333 |
|
|
|
334 |
case 4:
|
|
|
335 |
$ret .= $this->_sep . 'catorce';
|
|
|
336 |
break;
|
|
|
337 |
|
|
|
338 |
case 5:
|
|
|
339 |
$ret .= $this->_sep . 'quince';
|
|
|
340 |
break;
|
|
|
341 |
|
|
|
342 |
case 6:
|
|
|
343 |
case 7:
|
|
|
344 |
case 9:
|
|
|
345 |
case 8:
|
|
|
346 |
$ret .= $this->_sep . 'dieci' . $this->_digits[$d];
|
|
|
347 |
break;
|
|
|
348 |
}
|
|
|
349 |
break;
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
// add digits only if it is a multiple of 10 and not 1x or 2x
|
|
|
353 |
if (($t != 1) and ($t != 2) and ($d > 0)) {
|
|
|
354 |
|
|
|
355 |
// don't add 'y' for numbers below 10
|
|
|
356 |
if ($t != 0) {
|
|
|
357 |
// use 'un' instead of 'uno' when there is a suffix ('mil', 'millones', etc...)
|
|
|
358 |
if (($power > 0) and ($d == 1)) {
|
|
|
359 |
$ret .= $this->_sep.' y un';
|
|
|
360 |
} else {
|
|
|
361 |
$ret .= $this->_sep.'y '.$this->_digits[$d];
|
|
|
362 |
}
|
|
|
363 |
} else {
|
|
|
364 |
if (($power > 0) and ($d == 1)) {
|
|
|
365 |
$ret .= $this->_sep.'un';
|
|
|
366 |
} else {
|
|
|
367 |
$ret .= $this->_sep.$this->_digits[$d];
|
|
|
368 |
}
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
if ($power > 0) {
|
|
|
373 |
if (isset($this->_exponent[$power])) {
|
|
|
374 |
$lev = $this->_exponent[$power];
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
if (!isset($lev) || !is_array($lev)) {
|
|
|
378 |
return null;
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
// if it's only one use the singular suffix
|
|
|
382 |
if (($d == 1) and ($t == 0) and ($h == 0)) {
|
|
|
383 |
$suffix = $lev[0];
|
|
|
384 |
} else {
|
|
|
385 |
$suffix = $lev[1];
|
|
|
386 |
}
|
|
|
387 |
if ($num != 0) {
|
|
|
388 |
$ret .= $this->_sep . $suffix;
|
|
|
389 |
}
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
if ($dec) {
|
|
|
393 |
$dec = $this->toWords(trim($dec));
|
|
|
394 |
$ret .= ' con ' . trim($dec);
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
return $ret;
|
|
|
398 |
}
|
|
|
399 |
// }}}
|
|
|
400 |
|
|
|
401 |
// {{{ toCurrencyWords()
|
|
|
402 |
|
|
|
403 |
/**
|
|
|
404 |
* Converts a currency value to its word representation
|
|
|
405 |
* (with monetary units) in Agentinian Spanish language
|
|
|
406 |
*
|
|
|
407 |
* @param integer $int_curr An international currency symbol
|
|
|
408 |
* as defined by the ISO 4217 standard (three characters)
|
|
|
409 |
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
|
|
410 |
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
|
|
411 |
* Optional. Defaults to false.
|
|
|
412 |
* @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
|
|
|
413 |
* Optional. Defaults to true.
|
|
|
414 |
*
|
|
|
415 |
* @return string The corresponding word representation for the currency
|
|
|
416 |
*
|
|
|
417 |
* @access public
|
|
|
418 |
* @author Martin Marrese
|
|
|
419 |
*/
|
|
|
420 |
function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
|
|
|
421 |
{
|
|
|
422 |
$int_curr = strtoupper($int_curr);
|
|
|
423 |
if (!isset($this->_currency_names[$int_curr])) {
|
|
|
424 |
$int_curr = $this->def_currency;
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
$curr_names = $this->_currency_names[$int_curr];
|
|
|
428 |
|
|
|
429 |
$lev = ($decimal == 1) ? 0 : 1;
|
|
|
430 |
if ($lev > 0) {
|
|
|
431 |
if (count($curr_names[0]) > 1) {
|
|
|
432 |
$ret = $curr_names[0][$lev];
|
|
|
433 |
} else {
|
|
|
434 |
$ret = $curr_names[0][0] . 's';
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
} else {
|
|
|
438 |
$ret = $curr_names[0][0];
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
$ret .= $this->_sep . trim($this->toWords($decimal));
|
|
|
442 |
|
|
|
443 |
if ($fraction !== false) {
|
|
|
444 |
if ($convert_fraction) {
|
|
|
445 |
$ret .= $this->_sep .'con'. $this->_sep . trim($this->toWords($fraction));
|
|
|
446 |
} else {
|
|
|
447 |
$ret .= $this->_sep .'con'. $this->_sep . $fraction;
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
$lev = ($fraction == 1) ? 0 : 1;
|
|
|
451 |
if ($lev > 0) {
|
|
|
452 |
if (count($curr_names[1]) > 1) {
|
|
|
453 |
$ret .= $this->_sep . $curr_names[1][$lev];
|
|
|
454 |
} else {
|
|
|
455 |
$ret .= $this->_sep . $curr_names[1][0] . 's';
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
} else {
|
|
|
459 |
$ret .= $this->_sep . $curr_names[1][0];
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
return $ret;
|
|
|
463 |
}
|
|
|
464 |
// }}}
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
}
|
|
|
469 |
?>
|