diff --git a/Numbers/Words.php b/Numbers/Words.php index 00322e6..6073aac 100644 --- a/Numbers/Words.php +++ b/Numbers/Words.php @@ -84,6 +84,13 @@ class Numbers_Words */ public $decimalPoint = '.'; + /** + * Use abbreviation as decimal name + * @var boolean + * @access public + */ + static public $useAbbrAsDecimalNames = false; + // }}} // {{{ toWords() @@ -189,10 +196,10 @@ function toCurrency($num, $locale = 'en_US', $intCurr = '', $decimalPoint = null } elseif ($len > 2) { // get the 3rd digit after the comma $round_digit = substr($currency[1], 2, 1); - + // cut everything after the 2nd digit $currency[1] = substr($currency[1], 0, 2); - + if ($round_digit >= 5) { // round up without losing precision include_once "Math/BigInteger.php"; @@ -278,13 +285,13 @@ public static function getLocales($locales = null) public static function loadLocale($locale, $requiredMethod) { $classname = 'Numbers_Words_Locale_' . $locale; - if (!class_exists($classname)) { + if (!class_exists($classname, false)) { $file = str_replace('_', '/', $classname) . '.php'; if (stream_resolve_include_path($file)) { include_once $file; } - if (!class_exists($classname)) { + if (!class_exists($classname, false)) { throw new Numbers_Words_Exception( 'Unable to load locale class ' . $classname ); diff --git a/Numbers/Words/Locale/en/US.php b/Numbers/Words/Locale/en/US.php index 55b5968..3279709 100644 --- a/Numbers/Words/Locale/en/US.php +++ b/Numbers/Words/Locale/en/US.php @@ -260,7 +260,7 @@ class Numbers_Words_Locale_en_US extends Numbers_Words '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()), + 'SKK' => array(array('Slovak koruna'), array('halier')), 'TRL' => array(array('lira'), array('kuru')), 'UAH' => array(array('hryvna'), array('cent')), 'USD' => array(array('dollar'), array('cent')), @@ -482,23 +482,33 @@ function _toWords($num, $power = 0, $powsuffix = '') */ function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) { - $int_curr = strtoupper($int_curr); - if (!isset($this->_currency_names[$int_curr])) { - $int_curr = $this->def_currency; - } - $curr_names = $this->_currency_names[$int_curr]; + if (is_array($int_curr)) + $curr_names = $int_curr; + else + { + $int_curr = strtoupper($int_curr); + if (!isset($this->_currency_names[$int_curr])) { + $int_curr = $this->def_currency; + } + $curr_names = $this->_currency_names[$int_curr]; + } $ret = trim($this->_toWords($decimal)); - $lev = ($decimal == 1) ? 0 : 1; - if ($lev > 0) { - if (count($curr_names[0]) > 1) { - $ret .= $this->_sep . $curr_names[0][$lev]; - } else { - $ret .= $this->_sep . $curr_names[0][0] . 's'; - } - } else { - $ret .= $this->_sep . $curr_names[0][0]; - } + if (Numbers_Words::$useAbbrAsDecimalNames) + $ret .= $this->_sep . $int_curr; + else + { + $lev = ($decimal == 1) ? 0 : 1; + if ($lev > 0) { + if (count($curr_names[0]) > 1) { + $ret .= $this->_sep . $curr_names[0][$lev]; + } else { + $ret .= $this->_sep . $curr_names[0][0] . 's'; + } + } else { + $ret .= $this->_sep . $curr_names[0][0]; + } + } if ($fraction !== false) { if ($convert_fraction) { diff --git a/Numbers/Words/Locale/lv.php b/Numbers/Words/Locale/lv.php index 81d0c84..42b8dda 100755 --- a/Numbers/Words/Locale/lv.php +++ b/Numbers/Words/Locale/lv.php @@ -108,6 +108,56 @@ class Numbers_Words_Locale_lv extends Numbers_Words */ var $_sep = ' '; + /** + * The currency names (based on the below links, + * informations from central bank websites and on encyclopedias) + * + * @var array + * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies + * @link http://www.rusimpex.ru/Content/Reference/Refinfo/valuta.htm Foreign currencies names + * @link http://www.cofe.ru/Finance/money.asp Currencies names + * @access private + */ + // TODO: recheck + var $_currency_names = array( + 'ALL' => array(array('lek'), array('qindarka')), + 'AUD' => array(array('Austrālijas dolārs', 'Austrālijas dolāri'), array('cents', 'centi')), + 'BAM' => array(array('konvertējamas marka'), array('fenig')), + 'BGN' => array(array('lev'), array('stotinka')), + 'BRL' => array(array('real'), array('centavos')), + 'BYR' => array(array('Baltkrievijas rublis', 'Baltkrievijas rubļi'), array('kapeika', 'kapeikās')), + 'CAD' => array(array('Kanādas dolārs', 'Kanādas dolāri'), array('cents', 'centi')), + 'CHF' => array(array('Šveices franks', 'Šveices franki'), array('rapp')), + 'CYP' => array(array('Kipras mārciņa', 'Kipras mārciņas'), array('cents', 'centi')), + 'CZK' => array(array('Čehijas krona', 'Čehijas kronās'), array('halerz')), + 'DKK' => array(array('Dāniska krona', 'Dāniskas kronas'), array('ore')), + 'EEK' => array(array('kroon'), array('senti')), + 'EUR' => array(array('eiro'), array('eiro-cents', 'eiro-centi')), + 'GBP' => array(array('mārciņa', 'mārciņas'), array('pensi')), + 'HKD' => array(array('Honkongas dolārs', 'Honkongas dolāri'), array('cent')), + 'HRK' => array(array('Horvātijas kuna', 'Horvātijas kunas'), array('lipa')), + 'HUF' => array(array('forint'), array('filler')), + 'ILS' => array(array('jauna šekelis','jauni šekeli'), array('agora','agorot')), + 'ISK' => array(array('Islandes krona', 'Islandes kronas'), array('aurar')), + 'JPY' => array(array('yen'), array('sen')), + 'LTL' => array(array('lit'), array('cents', 'centi')), + 'LVL' => array(array('lat'), array('sentim')), + 'MKD' => array(array('Maķedonijas dinārs', 'Maķedonijas dināri'), array('deni')), + 'MTL' => array(array('Maltas lira', 'Maltas liras'), array('centym')), + 'NOK' => array(array('Norvēģiska krona', 'Norvēģiskas kronas'), array('oere')), + 'PLN' => array(array('zlot'), array('grosz')), + 'ROL' => array(array('Rumānijas leja', 'Rumānijas lejas'), array('bani')), + 'RUB' => array(array('Krievijas rublis', 'Krievijas rubļi'), array('kapeika', 'kapeikās')), + 'SEK' => array(array('Zviedru krona', 'Zviedru kronas'), array('oere')), + 'SIT' => array(array('Tolars', 'Tolari'), array('stotinia')), + 'SKK' => array(array('Slovākijas krona', 'Slovākijas kronas'), array('halier')), + 'TRL' => array(array('lira'), array('kuruю')), + 'UAH' => array(array('hryvna'), array('cents', 'centi')), + 'USD' => array(array('dolārs'), array('cents', 'centi')), + 'YUM' => array(array('dinārs', 'dinārsi'), array('para')), + 'ZAR' => array(array('rand'), array('cents', 'centi')) + ); + /** * The default currency name * @var string @@ -315,5 +365,74 @@ function _toWords($num, $power = 0, $powsuffix = '') return $ret; } // }}} + // {{{ toCurrencyWords() + + /** + * Converts a currency value to its word representation + * (with monetary units) in Latvian 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 MaxB + */ + function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) + { + if (is_array($int_curr)) + $curr_names = $int_curr; + else + { + $int_curr = strtoupper($int_curr); + if (!isset($this->_currency_names[$int_curr])) { + $int_curr = $this->def_currency; + } + $curr_names = $this->_currency_names[$int_curr]; + } + + $ret = trim($this->_toWords($decimal)); + if (Numbers_Words::$useAbbrAsDecimalNames) + $ret .= $this->_sep . $int_curr; + else + { + $lev = ($decimal == 1) ? 0 : 1; + if ($lev > 0) { + if (count($curr_names[0]) > 1) { + $ret .= $this->_sep . $curr_names[0][$lev]; + } else { + $ret .= $this->_sep . $curr_names[0][0]; + } + } else { + $ret .= $this->_sep . $curr_names[0][0]; + } + } + + if ($fraction !== false) { + if ($convert_fraction) { + $ret .= $this->_sep . trim($this->_toWords($fraction)); + } else { + $ret .= $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]; + } + } else { + $ret .= $this->_sep . $curr_names[1][0]; + } + } + return $ret; + } + // }}} } diff --git a/Numbers/Words/Locale/ru.php b/Numbers/Words/Locale/ru.php index 112b705..558e92b 100644 --- a/Numbers/Words/Locale/ru.php +++ b/Numbers/Words/Locale/ru.php @@ -70,14 +70,14 @@ class Numbers_Words_Locale_ru extends Numbers_Words * @access public */ var $lang_native = 'Русский'; - + /** * The word for the minus sign * @var string * @access private */ var $_minus = 'минус'; // minus sign - + /** * The sufixes for exponents (singular) * Names partly based on: @@ -242,7 +242,7 @@ class Numbers_Words_Locale_ru extends Numbers_Words ); /** - * The array containing the digits + * The array containing the digits * for neutral, male and female * @var array * @access private @@ -272,7 +272,7 @@ class Numbers_Words_Locale_ru extends Numbers_Words */ var $_currency_names = array( 'ALL' => array( - array(1, 'лек', 'лека', 'леков'), + array(1, 'лек', 'лека', 'леков'), array(2, 'киндарка', 'киндарки', 'киндарок') ), 'AUD' => array( @@ -280,15 +280,15 @@ class Numbers_Words_Locale_ru extends Numbers_Words array(1, 'цент', 'цента', 'центов') ), 'BGN' => array( - array(1, 'лев', 'лева', 'левов'), + array(1, 'лев', 'лева', 'левов'), array(2, 'стотинка', 'стотинки', 'стотинок') ), 'BRL' => array( - array(1, 'бразильский реал', 'бразильских реала', 'бразильских реалов'), + array(1, 'бразильский реал', 'бразильских реала', 'бразильских реалов'), array(1, 'сентаво', 'сентаво', 'сентаво') ), 'BYR' => array( - array(1, 'белорусский рубль', 'белорусских рубля', 'белорусских рублей'), + array(1, 'белорусский рубль', 'белорусских рубля', 'белорусских рублей'), array(2, 'копейка', 'копейки', 'копеек') ), 'CAD' => array( @@ -439,7 +439,7 @@ class Numbers_Words_Locale_ru extends Numbers_Words * @author Andrey Demenev * @since Numbers_Words 0.16.3 */ - function _toWords($num, $options = array()) + function _toWords($num, $options = array()) { $dummy = null; $gender = 1; @@ -472,9 +472,9 @@ function _toWordsWithCase($num, &$case, $gender = 1) { $ret = ''; $case = 3; - + $num = trim($num); - + $sign = ""; if (substr($num, 0, 1) == '-') { $sign = $this->_minus . $this->_sep; @@ -552,7 +552,7 @@ function _toWordsWithCase($num, &$case, $gender = 1) */ function _groupToWords($num, $gender, &$case) { - $ret = ''; + $ret = ''; $case = 3; if ((int)$num == 0) { @@ -562,7 +562,7 @@ function _groupToWords($num, $gender, &$case) if ($num == 1) { $case = 1; } elseif ($num < 5) { - $case = 2; + $case = 2; } else { $case = 3; } @@ -632,15 +632,23 @@ function _groupToWords($num, $gender, &$case) */ function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) { - $int_curr = strtoupper($int_curr); - if (!isset($this->_currency_names[$int_curr])) { - $int_curr = $this->def_currency; - } - - $curr_names = $this->_currency_names[$int_curr]; - + if (is_array($int_curr)) + $curr_names = $int_curr; + else + { + $int_curr = strtoupper($int_curr); + if (!isset($this->_currency_names[$int_curr])) { + $int_curr = $this->def_currency; + } + $curr_names = $this->_currency_names[$int_curr]; + } + + $case = null; $ret = trim($this->_toWordsWithCase($decimal, $case, $curr_names[0][0])); - $ret .= $this->_sep . $curr_names[0][$case]; + if (Numbers_Words::$useAbbrAsDecimalNames) + $ret .= $this->_sep . $int_curr; + else + $ret .= $this->_sep . $curr_names[0][$case]; if ($fraction !== false) { if ($convert_fraction) {