2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
4 // +----------------------------------------------------------------------+
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 1997-2003 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 // | Authors: Martin Marrese <mmare@mecon.gov.ar> |
18 // | Based On: lang_es.php - Xavier Noguer |
19 // +----------------------------------------------------------------------+
22 // Numbers_Words class extension to spell numbers in Argentinian Spanish
28 * Class for translating numbers into Spanish (Castellano).
30 * @author Martin Marrese
31 * @package Numbers_Words
35 * Include needed files
37 require_once("Numbers/Words.php");
40 * Class for translating numbers into Spanish (Castellano).
41 * It supports up to decallones (10^6).
42 * It doesn't support spanish tonic accents (acentos).
44 * @author Martin Marrese
45 * @package Numbers_Words
47 class Numbers_Words_es_AR extends Numbers_Words
56 var $locale = 'es_AR';
59 * Language name in English
63 var $lang = 'Spanish';
66 * Native language name
70 var $lang_native = 'Español';
73 * The word for the minus sign
77 var $_minus = 'menos';
80 * The sufixes for exponents (singular and plural)
84 var $_exponent = array(
86 3 => array('mil','mil'),
87 6 => array('millón','millones'),
88 12 => array('billón','billones'),
89 18 => array('trilón','trillones'),
90 24 => array('cuatrillón','cuatrillones'),
91 30 => array('quintillón','quintillones'),
92 36 => array('sextillón','sextillones'),
93 42 => array('septillón','septillones'),
94 48 => array('octallón','octallones'),
95 54 => array('nonallón','nonallones'),
96 60 => array('decallón','decallones'),
99 * The array containing the digits (indexed by the digits themselves).
103 var $_digits = array(
104 0 => 'cero', 'uno', 'dos', 'tres', 'cuatro',
105 'cinco', 'seis', 'siete', 'ocho', 'nueve'
115 * The currency names (based on the below links,
116 * informations from central bank websites and on encyclopedias)
119 * @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
120 * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
121 * @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
124 var $_currency_names = array(
125 'ALL' => array(array('lek'), array('qindarka')),
126 'AUD' => array(array('Australian dollar'), array('cent')),
127 'ARS' => array(array('Peso'), array ('centavo')),
128 'BAM' => array(array('convertible marka'), array('fenig')),
129 'BGN' => array(array('lev'), array('stotinka')),
130 'BRL' => array(array('real'), array('centavos')),
131 'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
132 'CAD' => array(array('Canadian dollar'), array('cent')),
133 'CHF' => array(array('Swiss franc'), array('rapp')),
134 'CYP' => array(array('Cypriot pound'), array('cent')),
135 'CZK' => array(array('Czech koruna'), array('halerz')),
136 'DKK' => array(array('Danish krone'), array('ore')),
137 'EEK' => array(array('kroon'), array('senti')),
138 'EUR' => array(array('euro'), array('euro-cent')),
139 'GBP' => array(array('pound', 'pounds'), array('pence')),
140 'HKD' => array(array('Hong Kong dollar'), array('cent')),
141 'HRK' => array(array('Croatian kuna'), array('lipa')),
142 'HUF' => array(array('forint'), array('filler')),
143 'ISK' => array(array('Icelandic króna'), array('aurar')),
144 'JPY' => array(array('yen'), array('sen')),
145 'LTL' => array(array('litas'), array('cent')),
146 'LVL' => array(array('lat'), array('sentim')),
147 'MKD' => array(array('Macedonian dinar'), array('deni')),
148 'MTL' => array(array('Maltese lira'), array('centym')),
149 'NOK' => array(array('Norwegian krone'), array('oere')),
150 'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
151 'ROL' => array(array('Romanian leu'), array('bani')),
152 'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
153 'SEK' => array(array('Swedish krona'), array('oere')),
154 'SIT' => array(array('Tolar'), array('stotinia')),
155 'SKK' => array(array('Slovak koruna'), array()),
156 'TRL' => array(array('lira'), array('kuruþ')),
157 'UAH' => array(array('hryvna'), array('cent')),
158 'USD' => array(array('dollar'), array('cent')),
159 'YUM' => array(array('dinars'), array('para')),
160 'ZAR' => array(array('rand'), array('cent'))
164 * The default currency name
168 var $def_currency = 'ARS'; // Argentinian Peso
173 * Converts a number to its word representation
174 * in Spanish (Castellano).
176 * @param float $num An float between -infinity and infinity inclusive :)
177 * that should be converted to a words representation
178 * @param integer $power The power of ten for the rest of the number to the right.
179 * For example toWords(12,3) should give "doce mil".
180 * Optional, defaults to 0.
181 * @return string The corresponding word representation
184 * @author Martin Marrese
186 function toWords($num, $power = 0)
188 // The return string;
191 // add a the word for the minus sign if necessary
192 if (substr($num, 0, 1) == '-')
194 $ret = $this->_sep . $this->_minus;
195 $num = substr($num, 1);
199 // strip excessive zero signs
200 $num = preg_replace('/^0+/','',$num);
202 $num_tmp = split ('\.', $num);
205 $dec = (@$num_tmp[1]) ? $num_tmp[1] : '';
207 if (strlen($num) > 6)
210 // check for highest power
211 if (isset($this->_exponent[$power]))
213 // convert the number above the first 6 digits
214 // with it's corresponding $power.
215 $snum = substr($num, 0, -6);
216 $snum = preg_replace('/^0+/','',$snum);
218 $ret .= $this->toWords($snum, $power + 6);
221 $num = substr($num, -6);
226 elseif ($num == 0 || $num == '') {
227 return(' '.$this->_digits[0]);
228 $current_power = strlen($num);
231 $current_power = strlen($num);
234 // See if we need "thousands"
235 $thousands = floor($num / 1000);
236 if ($thousands == 1) {
237 $ret .= $this->_sep . 'mil';
239 elseif ($thousands > 1) {
240 $ret .= $this->toWords($thousands, 3);
243 // values for digits, tens and hundreds
244 $h = floor(($num / 100) % 10);
245 $t = floor(($num / 10) % 10);
246 $d = floor($num % 10);
248 // cientos: doscientos, trescientos, etc...
252 if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
253 $ret .= $this->_sep . 'cien';
256 $ret .= $this->_sep . 'ciento';
264 $ret .= $this->_sep . $this->_digits[$h] . 'cientos';
267 $ret .= $this->_sep . 'quinientos';
270 $ret .= $this->_sep . 'setecientos';
273 $ret .= $this->_sep . 'novecientos';
277 // decenas: veinte, treinta, etc...
281 $ret .= $this->_sep . 'noventa';
285 $ret .= $this->_sep . 'ochenta';
289 $ret .= $this->_sep . 'setenta';
293 $ret .= $this->_sep . 'sesenta';
297 $ret .= $this->_sep . 'cincuenta';
301 $ret .= $this->_sep . 'cuarenta';
305 $ret .= $this->_sep . 'treinta';
310 $ret .= $this->_sep . 'veinte';
313 if (($power > 0) and ($d == 1)) {
314 $ret .= $this->_sep . 'veintiún';
317 $ret .= $this->_sep . 'veinti' . $this->_digits[$d];
326 $ret .= $this->_sep . 'diez';
330 $ret .= $this->_sep . 'once';
334 $ret .= $this->_sep . 'doce';
338 $ret .= $this->_sep . 'trece';
342 $ret .= $this->_sep . 'catorce';
346 $ret .= $this->_sep . 'quince';
353 $ret .= $this->_sep . 'dieci' . $this->_digits[$d];
359 // add digits only if it is a multiple of 10 and not 1x or 2x
360 if (($t != 1) and ($t != 2) and ($d > 0))
362 if($t != 0) // don't add 'y' for numbers below 10
364 // use 'un' instead of 'uno' when there is a suffix ('mil', 'millones', etc...)
365 if(($power > 0) and ($d == 1)) {
366 $ret .= $this->_sep.' y un';
369 $ret .= $this->_sep.'y '.$this->_digits[$d];
373 if(($power > 0) and ($d == 1)) {
374 $ret .= $this->_sep.'un';
377 $ret .= $this->_sep.$this->_digits[$d];
384 if (isset($this->_exponent[$power])) {
385 $lev = $this->_exponent[$power];
388 if (!isset($lev) || !is_array($lev)) {
392 // if it's only one use the singular suffix
393 if (($d == 1) and ($t == 0) and ($h == 0)) {
400 $ret .= $this->_sep . $suffix;
405 $dec = $this->toWords(trim($dec));
406 $ret.= ' con ' . trim ($dec);
416 * Converts a currency value to its word representation
417 * (with monetary units) in Agentinian Spanish language
419 * @param integer $int_curr An international currency symbol
420 * as defined by the ISO 4217 standard (three characters)
421 * @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
422 * @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
423 * Optional. Defaults to false.
425 * @return string The corresponding word representation for the currency
428 * @author Martin Marrese
430 function toCurrencyWords($int_curr, $decimal, $fraction = false) {
431 $int_curr = strtoupper($int_curr);
432 if (!isset($this->_currency_names[$int_curr])) {
433 $int_curr = $this->def_currency;
435 $curr_names = $this->_currency_names[$int_curr];
436 $lev = ($decimal == 1) ? 0 : 1;
438 if (count($curr_names[0]) > 1) {
439 $ret = $curr_names[0][$lev];
441 $ret = $curr_names[0][0] . 's';
444 $ret = $curr_names[0][0];
446 $ret .= $this->_sep . trim($this->toWords($decimal));
448 if ($fraction !== false) {
449 $ret .= $this->_sep .'con'. $this->_sep . trim($this->toWords($fraction));
450 $lev = ($fraction == 1) ? 0 : 1;
452 if (count($curr_names[1]) > 1) {
453 $ret .= $this->_sep . $curr_names[1][$lev];
455 $ret .= $this->_sep . $curr_names[1][0] . 's';
458 $ret .= $this->_sep . $curr_names[1][0];