Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7dad8d2e55
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 466 lines (413 sloc) 14.699 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
<?php
/**
* Numbers_Words
*
* PHP version 4
*
* Copyright (c) 1997-2006 The PHP Group
*
* This source file is subject to version 3.01 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/3_01.txt
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license@php.net so we can mail you a copy immediately.
*
* @category Numbers
* @package Numbers_Words
* @author Pavel Oropeza <pavel@cognus.ath.cx>
* @author Martin Marrese <mmare@mecon.gov.ar>
* @license PHP 3.01 http://www.php.net/license/3_01.txt
* @version SVN: $Id: lang.es_AR.php 269823 2008-11-25 13:47:38Z clockwerx $
* @link http://pear.php.net/package/Numbers_Words
*/

/**
* Class for translating numbers into Mexican Spanish.
*
* @author Martin Marrese
* @package Numbers_Words
*/

/**
* Include needed files
*/
require_once "Numbers/Words.php";

/**
* Class for translating numbers into Argentinian Spanish.
* It supports up to decallones (10^6).
* It doesn't support spanish tonic accents (acentos).
*
* @category Numbers
* @package Numbers_Words
* @author Pavel Oropeza <pavel@cognus.ath.cx>
* @author Martin Marrese <mmare@mecon.gov.ar>
* @license PHP 3.01 http://www.php.net/license/3_01.txt
* @link http://pear.php.net/package/Numbers_Words
*/
class Numbers_Words_es_MX extends Numbers_Words
{
    // {{{ properties

    /**
* Locale name
* @var string
* @access public
*/
    var $locale = 'es_MX';

    /**
* Language name in English
* @var string
* @access public
*/
    var $lang = 'Spanish';

    /**
* Native language name
* @var string
* @access public
*/
    var $lang_native = 'Español';

    /**
* The word for the minus sign
* @var string
* @access private
*/
    var $_minus = 'menos';

    /**
* The sufixes for exponents (singular and plural)
* @var array
* @access private
*/
    var $_exponent = array(
        0 => array('',''),
        3 => array('mil','mil'),
        6 => array('millón','millones'),
       12 => array('billón','billones'),
       18 => array('trilón','trillones'),
       24 => array('cuatrillón','cuatrillones'),
       30 => array('quintillón','quintillones'),
       36 => array('sextillón','sextillones'),
       42 => array('septillón','septillones'),
       48 => array('octallón','octallones'),
       54 => array('nonallón','nonallones'),
       60 => array('decallón','decallones'),
        );
    /**
* The array containing the digits (indexed by the digits themselves).
* @var array
* @access private
*/
    var $_digits = array(
        0 => 'cero', 'un', 'dos', 'tres', 'cuatro',
        'cinco', 'seis', 'siete', 'ocho', 'nueve'
        );
    /**
* The word separator
* @var string
* @access private
*/
    var $_sep = ' ';

    /**
* The currency names (based on the below links,
* informations from central bank websites and on encyclopedias)
*
* @var array
* @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
* @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
* @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
* @access private
*/
    var $_currency_names = array(
      'ALL' => array(array('lek'), array('qindarka')),
      'AUD' => array(array('Australian dollar'), array('cent')),
      'ARS' => array(array('Peso'), array ('centavo')),
      'BAM' => array(array('convertible marka'), array('fenig')),
      'BGN' => array(array('lev'), array('stotinka')),
      'BRL' => array(array('real'), array('centavos')),
      'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
      'CAD' => array(array('Canadian dollar'), array('cent')),
      'CHF' => array(array('Swiss franc'), array('rapp')),
      'CYP' => array(array('Cypriot pound'), array('cent')),
      'CZK' => array(array('Czech koruna'), array('halerz')),
      'DKK' => array(array('Danish krone'), array('ore')),
      'EEK' => array(array('kroon'), array('senti')),
      'EUR' => array(array('euro'), array('euro-cent')),
      'GBP' => array(array('pound', 'pounds'), array('pence')),
      'HKD' => array(array('Hong Kong dollar'), array('cent')),
      'HRK' => array(array('Croatian kuna'), array('lipa')),
      'HUF' => array(array('forint'), array('filler')),
      'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
      'ISK' => array(array('Icelandic króna'), array('aurar')),
      'JPY' => array(array('yen'), array('sen')),
      'LTL' => array(array('litas'), array('cent')),
      'LVL' => array(array('lat'), array('sentim')),
      'MKD' => array(array('Macedonian dinar'), array('deni')),
      'MTL' => array(array('Maltese lira'), array('centym')),
      'MXN' => array(array('peso'), array ('centavo')),
      'NOK' => array(array('Norwegian krone'), array('oere')),
      'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
      'ROL' => array(array('Romanian leu'), array('bani')),
      'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
      'SEK' => array(array('Swedish krona'), array('oere')),
      'SIT' => array(array('Tolar'), array('stotinia')),
      'SKK' => array(array('Slovak koruna'), array()),
      'TRL' => array(array('lira'), array('kuruþ')),
      'UAH' => array(array('hryvna'), array('cent')),
      'USD' => array(array('dollar'), array('cent')),
      'YUM' => array(array('dinars'), array('para')),
      'ZAR' => array(array('rand'), array('cent'))
    );

    /**
* The default currency name
* @var string
* @access public
*/
    var $def_currency = 'MXN'; // Mexican Peso

    // }}}
    // {{{ _toWords()
    /**
* Converts a number to its word representation
* in Mexican Spanish.
*
* @param float $num An float between -infinity and infinity inclusive :)
* that should be converted to a words representation
* @param integer $power The power of ten for the rest of the number to the right.
* For example toWords(12,3) should give "doce mil".
* Optional, defaults to 0.
*
* @return string The corresponding word representation
*
* @access protected
* @author Martin Marrese
* @since Numbers_Words 0.16.3
*/
    function _toWords($num, $power = 0)
    {
        // The return string;
        $ret = '';

        // add a the word for the minus sign if necessary
        if (substr($num, 0, 1) == '-') {
            $ret = $this->_sep . $this->_minus;
            $num = substr($num, 1);
        }


        // strip excessive zero signs
        $num = preg_replace('/^0+/', '', $num);

        $num_tmp = explode('.', $num);

        $num = $num_tmp[0];
        $dec = (@$num_tmp[1]) ? $num_tmp[1] : '';

        if (strlen($num) > 6) {
            $current_power = 6;
            // check for highest power
            if (isset($this->_exponent[$power])) {
                // convert the number above the first 6 digits
                // with it's corresponding $power.
                $snum = substr($num, 0, -6);
                $snum = preg_replace('/^0+/', '', $snum);
                if ($snum !== '') {
                    $ret .= $this->_toWords($snum, $power + 6);
                }
            }
            $num = substr($num, -6);
            if ($num == 0) {
                return $ret;
            }
        } elseif ($num == 0 || $num == '') {
            return(' '.$this->_digits[0]);
            $current_power = strlen($num);
        } else {
            $current_power = strlen($num);
        }

        // See if we need "thousands"
        $thousands = floor($num / 1000);
        if ($thousands == 1) {
            $ret .= $this->_sep . 'mil';
        } elseif ($thousands > 1) {
            $ret .= $this->_toWords($thousands, 3);
        }

        // values for digits, tens and hundreds
        $h = floor(($num / 100) % 10);
        $t = floor(($num / 10) % 10);
        $d = floor($num % 10);

        // cientos: doscientos, trescientos, etc...
        switch ($h) {
        case 1:
            if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
                $ret .= $this->_sep . 'cien';
            } else {
                $ret .= $this->_sep . 'ciento';
            }
            break;
        case 2:
        case 3:
        case 4:
        case 6:
        case 8:
            $ret .= $this->_sep . $this->_digits[$h] . 'cientos';
            break;
        case 5:
            $ret .= $this->_sep . 'quinientos';
            break;
        case 7:
            $ret .= $this->_sep . 'setecientos';
            break;
        case 9:
            $ret .= $this->_sep . 'novecientos';
            break;
        }

        // decenas: veinte, treinta, etc...
        switch ($t) {
        case 9:
            $ret .= $this->_sep . 'noventa';
            break;

        case 8:
            $ret .= $this->_sep . 'ochenta';
            break;

        case 7:
            $ret .= $this->_sep . 'setenta';
            break;

        case 6:
            $ret .= $this->_sep . 'sesenta';
            break;

        case 5:
            $ret .= $this->_sep . 'cincuenta';
            break;

        case 4:
            $ret .= $this->_sep . 'cuarenta';
            break;

        case 3:
            $ret .= $this->_sep . 'treinta';
            break;

        case 2:
            if ($d == 0) {
                $ret .= $this->_sep . 'veinte';
            } else {
                if (($power > 0) and ($d == 1)) {
                    $ret .= $this->_sep . 'veintiún';
                } else {
                    $ret .= $this->_sep . 'veinti' . $this->_digits[$d];
                }
            }
            break;

        case 1:
            switch ($d) {
            case 0:
                $ret .= $this->_sep . 'diez';
                break;

            case 1:
                $ret .= $this->_sep . 'once';
                break;

            case 2:
                $ret .= $this->_sep . 'doce';
                break;

            case 3:
                $ret .= $this->_sep . 'trece';
                break;

            case 4:
                $ret .= $this->_sep . 'catorce';
                break;

            case 5:
                $ret .= $this->_sep . 'quince';
                break;

            case 6:
            case 7:
            case 9:
            case 8:
                $ret .= $this->_sep . 'dieci' . $this->_digits[$d];
                break;
            }
            break;
        }

        // add digits only if it is a multiple of 10 and not 1x or 2x
        if (($t != 1) and ($t != 2) and ($d > 0)) {

            // don't add 'y' for numbers below 10
            if ($t != 0) {
                // use 'un' instead of 'uno' when there is a suffix ('mil', 'millones', etc...)
                if (($power > 0) and ($d == 1)) {
                    $ret .= $this->_sep.' y un';
                } else {
                    $ret .= $this->_sep.'y '.$this->_digits[$d];
                }
            } else {
                if (($power > 0) and ($d == 1)) {
                    $ret .= $this->_sep.'un';
                    
                } else {
                    $ret .= $this->_sep.$this->_digits[$d];
                }
            }
        }

        if ($power > 0) {
            if (isset($this->_exponent[$power])) {
                $lev = $this->_exponent[$power];
            }

            if (!isset($lev) || !is_array($lev)) {
                return null;
            }

            // if it's only one use the singular suffix
            if (($d == 1) and ($t == 0) and ($h == 0)) {
                $suffix = $lev[0];
            } else {
                $suffix = $lev[1];
            }
            if ($num != 0) {
                $ret .= $this->_sep . $suffix;
            }
        }

        if ($dec) {
            $dec = $this->_toWords(trim($dec));
            $ret .= ' con ' . trim($dec);
        }

        return $ret;
    }
    

    /**
* Converts a currency value to its word representation
* (with monetary units) in Mexican Spanish language
*
* @param integer $int_curr An international currency symbol
* as defined by the ISO 4217 standard (three characters)
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
* Optional. Defaults to false.
* @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
* Optional. Defaults to true.
*
* @return string The corresponding word representation for the currency
*
* @access public
* @author Pavel Oropeza
*/
    function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
    {
        if (!isset($this->_currency_names[$int_curr])) {
            $int_curr = $this->def_currency;
        }

        $curr_names = $this->_currency_names[$int_curr];

        $lev = ($decimal == 1) ? 0 : 1;
        if ($lev > 0) {
            $curr_names = $this->_currency_names[$int_curr];
            if (count($curr_names[0]) > 1) {
                $ret = $curr_names[0][$lev];
            } else {
                $ret = $curr_names[0][0] . 's';
            }

        } else {
            $ret = $curr_names[0][0];
        }
        $ret = $this->_sep . ucfirst(trim($this->_toWords($decimal) ." " . $ret));

        if ($fraction !== false) {
            if ($convert_fraction) {
                $ret .= $this->_sep .'con'. $this->_sep . trim($this->_toWords($fraction));
            } else {
                $ret .= $this->_sep .'con'. $this->_sep . $fraction;
            }

            $lev = ($fraction == 1) ? 0 : 1;
            if ($lev > 0) {
                if (count($curr_names[1]) > 1) {
                    $ret .= $this->_sep . $curr_names[1][$lev];
                } else {
                    $ret .= $this->_sep . $curr_names[1][0] . 's';
                }

            } else {
                $ret .= $this->_sep . $curr_names[1][0];
            }
        }
        return $ret;
        
    }
}
Something went wrong with that request. Please try again.