/usr/share/php/Numbers/Words/Locale/pt/BR.php is in php-numbers-words 0.18.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Numbers_Words
*
* PHP version 5
*
* 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 Igor Feghali <ifeghali@php.net>
* @license PHP 3.01 http://www.php.net/license/3_01.txt
* @version SVN: $Id$
* @link http://pear.php.net/package/Numbers_Words
*/
/**
* Include needed files
*/
require_once "Numbers/Words.php";
/**
* Class for translating numbers into Brazilian Portuguese. This class complies
* to Brazilian Academy of Letters rules as of 2008-12-12.
*
* @category Numbers
* @package Numbers_Words
* @author Igor Feghali <ifeghali@php.net>
* @license PHP 3.01 http://www.php.net/license/3_01.txt
* @link http://pear.php.net/package/Numbers_Words
*/
class Numbers_Words_Locale_pt_BR extends Numbers_Words
{
/**
* Locale name
* @var string
* @access public
*/
var $locale = 'pt_BR';
/**
* Language name in English
* @var string
* @access public
*/
var $lang = 'Brazilian Portuguese';
/**
* Native language name
* @var string
* @access public
*/
var $lang_native = 'Português Brasileiro';
/**
* The word for the minus sign
* @var string
* @access private
*/
var $_minus = 'negativo';
/**
* The word separator for numerals
* @var string
* @access private
*/
var $_sep = ' e ';
/**
* The special separator for numbers and currency names
* @var string
* @access private
*/
var $_curr_sep = ' de ';
/**
* The array containing numbers 11-19.
* In Brazilian Portuguese numbers in that range are contracted
* in a single word.
* @var array
* @access private
*/
var $_contractions = array(
'',
'onze',
'doze',
'treze',
'quatorze',
'quinze',
'dezesseis',
'dezessete',
'dezoito',
'dezenove'
);
var $_words = array(
/**
* The array containing the digits (indexed by the digits themselves).
* @var array
* @access private
*/
array(
'', // 0: not displayed
'um',
'dois',
'três',
'quatro',
'cinco',
'seis',
'sete',
'oito',
'nove'
),
/**
* The array containing numbers for 10,20,...,90.
* @var array
* @access private
*/
array(
'', // 0: not displayed
'dez',
'vinte',
'trinta',
'quarenta',
'cinqüenta',
'sessenta',
'setenta',
'oitenta',
'noventa'
),
/**
* The array containing numbers for hundreds.
* @var array
* @access private
*/
array(
'', // 0: not displayed
'cento', // 'cem' is a special case handled in _toWords()
'duzentos',
'trezentos',
'quatrocentos',
'quinhentos',
'seiscentos',
'setecentos',
'oitocentos',
'novecentos'
),
);
/**
* The sufixes for exponents (singular)
* @var array
* @access private
*/
var $_exponent = array(
'', // 0: not displayed
'mil',
'milhão',
'bilhão',
'trilhão',
'quatrilhão',
'quintilhão',
'sextilhão',
'septilhão',
'octilhão',
'nonilhão',
'decilhão',
'undecilhão',
'dodecilhão',
'tredecilhão',
'quatuordecilhão',
'quindecilhão',
'sedecilhão',
'septendecilhão'
);
/**
* The currency names (based on Wikipedia) and plurals
*
* @var array
* @link http://pt.wikipedia.org/wiki/ISO_4217
* @access private
*/
var $_currency_names = array(
'BRL' => array(array('real', 'reais'), array('centavo', 'centavos')),
'USD' => array(array('dólar', 'dólares'), array('centavo', 'centavos')),
'EUR' => array(array('euro', 'euros'), array('centavo', 'centavos')),
'GBP' => array(array('libra esterlina', 'libras esterlinas'), array('centavo', 'centavos')),
'JPY' => array(array('iene', 'ienes'), array('centavo', 'centavos')),
'ARS' => array(array('peso argentino', 'pesos argentinos'), array('centavo', 'centavos')),
'MXN' => array(array('peso mexicano', 'pesos mexicanos'), array('centavo', 'centavos')),
'UYU' => array(array('peso uruguaio', 'pesos uruguaios'), array('centavo', 'centavos')),
'PYG' => array(array('guarani', 'guaranis'), array('centavo', 'centavos')),
'BOB' => array(array('boliviano', 'bolivianos'), array('centavo', 'centavos')),
'CLP' => array(array('peso chileno', 'pesos chilenos'), array('centavo', 'centavos')),
'COP' => array(array('peso colombiano', 'pesos colombianos'), array('centavo', 'centavos')),
'CUP' => array(array('peso cubano', 'pesos cubanos'), array('centavo', 'centavos')),
);
/**
* The default currency name
* @var string
* @access public
*/
var $def_currency = 'BRL'; // Real
// {{{ _toWords()
/**
* Converts a number to its word representation
* in Brazilian Portuguese language
*
* @param integer $num An integer between -999E54 and 999E54
*
* @return string The corresponding word representation
*
* @access protected
* @author Igor Feghali <ifeghali@php.net>
* @since Numbers_Words 0.16.3
*/
function _toWords($num)
{
$neg = 0;
$ret = array();
$words = array();
/**
* Negative ?
*/
if ($num < 0) {
$ret[] = $this->_minus;
$num = -$num;
$neg = 1;
}
/**
* Removes leading zeros, spaces, decimals etc.
* Adds thousands separator.
*/
$num = number_format($num, 0, '.', '.');
/**
* Testing Zero
*/
if ($num == 0) {
return 'zero';
}
/**
* Breaks into chunks of 3 digits.
* Reversing array to process from right to left.
*/
$chunks = array_reverse(explode(".", $num));
/**
* Looping through the chunks
*/
foreach ($chunks as $index => $chunk) {
/**
* Testing Range
*/
if (!array_key_exists($index, $this->_exponent)) {
throw new Numbers_Words_Exception('Number out of range.');
}
/**
* Testing Zero
*/
if ($chunk == 0) {
continue;
}
/**
* Testing plural of exponent
*/
if ($chunk > 1) {
$exponent = str_replace('ão', 'ões', $this->_exponent[$index]);
} else {
$exponent = $this->_exponent[$index];
}
/**
* Adding exponent
*/
$ret[] = $exponent;
/**
* Actual Number
*/
$word = array_filter($this->_parseChunk($chunk));
$ret[] = implode($this->_sep, $word);
}
/**
* In Brazilian Portuguese the last chunck must be separated under
* special conditions.
*/
if ((count($ret) > 2+$neg)
&& $this->_mustSeparate($chunks)) {
$ret[1+$neg] = trim($this->_sep.$ret[1+$neg]);
}
$ret = array_reverse(array_filter($ret));
return implode(' ', $ret);
}
// }}}
// {{{ _parseChunck()
/**
* Recursive function that parses an indivial chunk
*
* @param string $chunk String representation of a 3-digit-max number
*
* @return array Words of parsed number
*
* @access private
* @author Igor Feghali <ifeghali@php.net>
* @since Numbers_Words 0.15.1
*/
function _parseChunk($chunk)
{
/**
* Base Case
*/
if (!$chunk) {
return array();
}
/**
* 100 is a special case
*/
if ($chunk == 100) {
return array('cem');
}
/**
* Testing contractions (11~19)
*/
if (($chunk < 20) && ($chunk > 10)) {
return array($this->_contractions[$chunk % 10]);
}
$i = strlen($chunk)-1;
$n = (int)$chunk[0];
$word = $this->_words[$i][$n];
return array_merge(array($word), $this->_parseChunk(substr($chunk, 1)));
}
// }}}
// {{{ _mustSeparate()
/**
* In Brazilian Portuguese the last chunk must be separated from the others
* when it is a hundred (100, 200, 300 etc.) or less than 100.
*
* @param array $chunks Array of integers that contains all the chunks of
* the target number, in reverse order.
*
* @return boolean Returns true when last chunk must be separated
*
* @access private
* @author Igor Feghali <ifeghali@php.net>
* @since Numbers_Words 0.15.1
*/
function _mustSeparate($chunks)
{
$chunk = null;
/**
* Find first occurrence != 0.
* (first chunk in array but last logical chunk)
*/
reset($chunks);
do {
list(,$chunk) = each($chunks);
} while ($chunk === '000');
if (($chunk < 100) || !($chunk % 100)) {
return true;
}
return false;
}
// }}}
// {{{ toCurrencyWords()
/**
* Converts a currency value to its word representation
* (with monetary units) in Portuguese Brazilian
*
* @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 Igor Feghali <ifeghali@php.net>
* @since Numbers_Words 0.11.0
*/
function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
{
$neg = 0;
$ret = array();
$nodec = false;
/**
* Negative ?
* We can lose the '-' sign if we do the
* check after number_format() call (i.e. -0.01)
*/
if (substr($decimal, 0, 1) == '-') {
$decimal = -$decimal;
$neg = 1;
}
/**
* Removes leading zeros, spaces, decimals etc.
* Adds thousands separator.
*/
$num = number_format($decimal, 0, '', '');
/**
* Checking if given currency exists in driver.
* If not, use default currency
*/
$int_curr = strtoupper($int_curr);
if (!isset($this->_currency_name[$int_curr])) {
$int_curr = $this->def_currency;
}
/**
* Currency names and plural
*/
$curr_names = $this->_currency_names[$int_curr];
if ($num > 0) {
/**
* Word representation of decimal
*/
$ret[] = $this->_toWords($num);
/**
* Special case.
*/
if (substr($num, -6) == '000000') {
$ret[] = trim($this->_curr_sep);
}
/**
* Testing plural. Adding currency name
*/
if ($num > 1) {
$ret[] = $curr_names[0][1];
} else {
$ret[] = $curr_names[0][0];
}
}
/**
* Test if fraction was given and != 0
*/
$fraction = (int)$fraction;
if ($fraction) {
/**
* Removes leading zeros, spaces, decimals etc.
* Adds thousands separator.
*/
$num = number_format($fraction, 0, '.', '.');
/**
* Testing Range
*/
if ($num < 0 || $num > 99) {
throw new Numbers_Words_Exception('Fraction out of range.');
}
/**
* Have we got decimal?
*/
if (count($ret)) {
$ret[] = trim($this->_sep);
} else {
$nodec = true;
}
/**
* Word representation of fraction
*/
if ($convert_fraction) {
$ret[] = $this->_toWords($num);
} else {
$ret[] = $num;
}
/**
* Testing plural
*/
if ($num > 1) {
$ret[] = $curr_names[1][1];
} else {
$ret[] = $curr_names[1][0];
}
/**
* Have we got decimal?
* If not, include currency name after cents.
*/
if ($nodec) {
$ret[] = trim($this->_curr_sep);
$ret[] = $curr_names[0][0];
}
}
/**
* Negative ?
*/
if ($neg) {
$ret[] = $this->_minus;
}
return implode(' ', $ret);
}
// }}}
}
|