) I start to use PEAR Number_Word class, and it works greate! It convert numbers to a string by this way:
<?php
include_once 'Numbers/Words.php';
$number = 100254;
$nw = new Numbers_Words();
$numw = $nw->toWords($number);
print $numw;
?>
But now I need to convert the same number to a different languages at the same time. For exemple: I have number 100 and I need to convert it in the same time to English and French. I was trying to pass in the argument an array of two languages, but it's not work:
/**
* Default Locale name
* @var string
* @access public
*/
public $locale = 'en_US'; //__her I was try to pass an array, but no result__
/**
* Default decimal mark
* @var string
* @access public
*/
public $decimalPoint = '.';
// }}}
// {{{ toWords()
/**
* Converts a number to its word representation
*
* @param integer $num An integer between -infinity and infinity inclusive :)
* that should be converted to a words representation
* @param string $locale Language name abbreviation. Optional. Defaults to
* current loaded driver or en_US if any.
* @param array $options Specific driver options
*
* @access public
* @author Piotr Klaban <[email protected]>
* @since PHP 4.2.3
* @return string The corresponding word representation
*/
function toWords($num, $locale = '', $options = array())
{
if (empty($locale) && isset($this) && $this instanceof Numbers_Words) {
$locale = $this->locale;
}
if (empty($locale)) {
$locale = 'en_US';
}
$classname = self::loadLocale($locale, '_toWords');
$obj = new $classname;
if (!is_int($num)) {
$num = $obj->normalizeNumber($num);
// cast (sanitize) to int without losing precision
$num = preg_replace('/(.*?)('.preg_quote($obj->decimalPoint).'.*?)?$/', '$1', $num);
}
if (empty($options)) {
return trim($obj->_toWords($num));
}
return trim($obj->_toWords($num, $options));
}
Please, halp me if you know how! Thank you in advance!
Numbers_Words
does not support multiple languages at once.You need to create a new
Numbers_Words
instance for every language.