From 348a402617564529fe6190c634d8c6315934cd1e Mon Sep 17 00:00:00 2001 From: Aleksandar Dimitrov Date: Thu, 27 Aug 2020 15:56:34 +0300 Subject: [PATCH 1/3] feat: Added toCurrencyWords for Locale_bg --- Numbers/Words/Locale/bg.php | 119 ++++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 6 deletions(-) diff --git a/Numbers/Words/Locale/bg.php b/Numbers/Words/Locale/bg.php index 3b09e18..dec3593 100644 --- a/Numbers/Words/Locale/bg.php +++ b/Numbers/Words/Locale/bg.php @@ -77,7 +77,6 @@ class Numbers_Words_Locale_bg extends Numbers_Words 'hiliadi'=>'хиляди' // plural form of "thousand" ); - /** * The words for digits (except zero). Note that, there are three genders for them (neuter, masculine and feminine). * The words for 3 to 9 (masculine) and for 2 to 9 (feminine) are the same as neuter, so they're filled @@ -125,7 +124,7 @@ class Numbers_Words_Locale_bg extends Numbers_Words * @access private */ var $_and = 'и'; - + /** * The word separator. * @var string @@ -133,6 +132,54 @@ class Numbers_Words_Locale_bg 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://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('лек'), array('киндарка')), + 'AUD' => array(array('австралийски долар'), array('цент', 'цента')), + 'BAM' => array(array('конвертируема марка'), array('фенинг', 'фенинга')), + 'BGN' => array(array('лев', 'лева'), array('стотинка', 'сторинки')), + 'BRL' => array(array('реал', 'реала'), array('сентаво')), + 'BYR' => array(array('беларуска рубла', 'беларуска рубли'), array('копейка', 'копейки')), + 'CAD' => array(array('ланадски долар', 'ланадски долара'), array('цент', 'цента')), + 'CHF' => array(array('швейцарски франк', 'швейцарски франка'), array('сантим', 'сантима')), + 'CYP' => array(array('кипърски паунд', 'кипърски паунда'), array('цент', 'цента')), + 'CZK' => array(array('чешка крона', 'чешки крони'), array('халер', 'халера')), + 'DKK' => array(array('датска крона', 'датски крони'), array('йоре')), + 'EUR' => array(array('евро'), array('евро цент', 'евро цента')), + 'GBP' => array(array('паунд', 'паунда'), array('пенс', 'пенса')), + 'HKD' => array(array('хонг конгски долар', 'хонг конгски долара'), array('цент', 'цента')), + 'HRK' => array(array('хървадска куна', 'хървадска куни'), array('липа')), + 'HUF' => array(array('форинт', 'форинта'), array('филер', 'филера')), + 'ISK' => array(array('исландска крона', 'исландски крони'), array('ейре')), + 'JPY' => array(array('йена', 'йени'), array('сен')), + 'NOK' => array(array('Норвежка крона'), array('йоре')), + 'PLN' => array(array('злота', 'злоти'), array('грош', 'гроша')), + 'ROL' => array(array('лея', 'леи'), array('бани')), + 'RUB' => array(array('рубла', 'рубли'), array('копейка', 'копейки')), + 'SEK' => array(array('шведска крона'), array('йоре')), + 'SKK' => array(array('Словашка крона'), array()), + 'TRL' => array(array('лира', 'лири'), array('куруш', 'куруша')), + 'UAH' => array(array('гривня', 'гривни'), array('копейка', 'копейки')), + 'USD' => array(array('долар', 'долара'), array('цент', 'цента')), + 'YUM' => array(array('динар', 'динара'), array('пара')), + ); + + /** + * The default currency name + * @var string + * @access public + */ + var $def_currency = 'BGN'; // English pound + /** * The word for the minus sign. * @var string @@ -326,11 +373,11 @@ function _splitNumber($num) $ret =& $m[0]; if ($first) { - array_unshift($ret, $first); + array_unshift($ret, $first); } return $ret; } - + return explode(' ', number_format($num, 0, '', ' ')); // a faster version for integers } // }}} @@ -364,12 +411,12 @@ function _showDigitsGroup($num, $gender = 0, $last = false) the array may vary. */ $ret = array(); - + // extract the value of each digit from the three-digit number $e = $num%10; // ones $d = ($num-$e)%100/10; // tens $s = ($num-$d*10-$e)%1000/100; // hundreds - + // process the "hundreds" digit. if ($s) { switch ($s) { @@ -517,4 +564,64 @@ function _toWords($num = 0) return $ret_minus . rtrim(implode('', array_reverse($ret)), $this->_sep); } // }}} + // {{{ toCurrencyWords() + + /** + * Converts a currency value to its word representation + * (with monetary units) in English 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 Piotr Klaban + * @since Numbers_Words 0.13.1 + */ + 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]; + + $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 ($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] . 's'; + } + } else { + $ret .= $this->_sep . $curr_names[1][0]; + } + } + return $ret; + } + // }}} } From 06c01bf0a908f7d0cc8ac2060fb5975a48eea89e Mon Sep 17 00:00:00 2001 From: Aleksandar Dimitrov Date: Thu, 27 Aug 2020 16:00:49 +0300 Subject: [PATCH 2/3] fix: removed the 'S' from english --- Numbers/Words/Locale/bg.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Numbers/Words/Locale/bg.php b/Numbers/Words/Locale/bg.php index dec3593..d488e23 100644 --- a/Numbers/Words/Locale/bg.php +++ b/Numbers/Words/Locale/bg.php @@ -598,7 +598,7 @@ function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fracti if (count($curr_names[0]) > 1) { $ret .= $this->_sep . $curr_names[0][$lev]; } else { - $ret .= $this->_sep . $curr_names[0][0] . 's'; + $ret .= $this->_sep . $curr_names[0][0]; } } else { $ret .= $this->_sep . $curr_names[0][0]; @@ -615,7 +615,7 @@ function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fracti if (count($curr_names[1]) > 1) { $ret .= $this->_sep . $curr_names[1][$lev]; } else { - $ret .= $this->_sep . $curr_names[1][0] . 's'; + $ret .= $this->_sep . $curr_names[1][0]; } } else { $ret .= $this->_sep . $curr_names[1][0]; From 9b6828a36c81c353257ca2eba716ac8f7f75d465 Mon Sep 17 00:00:00 2001 From: Aleksandar Dimitrov Date: Thu, 27 Aug 2020 16:08:29 +0300 Subject: [PATCH 3/3] fix: added separator between the number and fraction --- Numbers/Words/Locale/bg.php | 90 +++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/Numbers/Words/Locale/bg.php b/Numbers/Words/Locale/bg.php index d488e23..7fb06cf 100644 --- a/Numbers/Words/Locale/bg.php +++ b/Numbers/Words/Locale/bg.php @@ -87,7 +87,7 @@ class Numbers_Words_Locale_bg extends Numbers_Words var $_digits = array( 0=>array(1=>"едно", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет"), // neuter 1=>array(1=>'един', 'два'), // masculine - -1=>array(1=>'една') // feminine + -1=>array(1=>'една') // feminine ); /** @@ -200,40 +200,40 @@ class Numbers_Words_Locale_bg extends Numbers_Words * @access private */ var $_exponent = array( - 0 => '', - 3 => 'хиляда', - 6 => 'милион', - 9 => 'милиард', - 12 => 'трилион', - 15 => 'квадрилион', - 18 => 'квинтилион', - 21 => 'секстилион', - 24 => 'септилион', - 27 => 'октилион', - 30 => 'ноналион', - 33 => 'декалион', - 36 => 'ундекалион', - 39 => 'дуодекалион', - 42 => 'тредекалион', - 45 => 'кватордекалион', - 48 => 'квинтдекалион', - 51 => 'сексдекалион', - 54 => 'септдекалион', - 57 => 'октодекалион', - 60 => 'новемдекалион', - 63 => 'вигинтилион', - 66 => 'унвигинтилион', - 69 => 'дуовигинтилион', - 72 => 'тревигинтилион', - 75 => 'кваторвигинтилион', - 78 => 'квинвигинтилион', - 81 => 'сексвигинтилион', - 84 => 'септенвигинтилион', - 87 => 'октовигинтилион', - 90 => 'новемвигинтилион', - 93 => 'тригинтилион', - 96 => 'унтригинтилион', - 99 => 'дуотригинтилион', + 0 => '', + 3 => 'хиляда', + 6 => 'милион', + 9 => 'милиард', + 12 => 'трилион', + 15 => 'квадрилион', + 18 => 'квинтилион', + 21 => 'секстилион', + 24 => 'септилион', + 27 => 'октилион', + 30 => 'ноналион', + 33 => 'декалион', + 36 => 'ундекалион', + 39 => 'дуодекалион', + 42 => 'тредекалион', + 45 => 'кватордекалион', + 48 => 'квинтдекалион', + 51 => 'сексдекалион', + 54 => 'септдекалион', + 57 => 'октодекалион', + 60 => 'новемдекалион', + 63 => 'вигинтилион', + 66 => 'унвигинтилион', + 69 => 'дуовигинтилион', + 72 => 'тревигинтилион', + 75 => 'кваторвигинтилион', + 78 => 'квинвигинтилион', + 81 => 'сексвигинтилион', + 84 => 'септенвигинтилион', + 87 => 'октовигинтилион', + 90 => 'новемвигинтилион', + 93 => 'тригинтилион', + 96 => 'унтригинтилион', + 99 => 'дуотригинтилион', 102 => 'третригинтилион', 105 => 'кватортригинтилион', 108 => 'квинтригинтилион', @@ -420,15 +420,15 @@ function _showDigitsGroup($num, $gender = 0, $last = false) // process the "hundreds" digit. if ($s) { switch ($s) { - case 1: - $ret[1] = $this->_misc_strings['sto']; - break; - case 2: - case 3: - $ret[1] = $this->_digits[0][$s].$this->_misc_strings['sta']; - break; - default: - $ret[1] = $this->_digits[0][$s].$this->_misc_strings['stotin']; + case 1: + $ret[1] = $this->_misc_strings['sto']; + break; + case 2: + case 3: + $ret[1] = $this->_digits[0][$s].$this->_misc_strings['sta']; + break; + default: + $ret[1] = $this->_digits[0][$s].$this->_misc_strings['stotin']; } } @@ -605,6 +605,8 @@ function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fracti } if ($fraction !== false) { + $ret .= $this->_sep . $this->_and; + if ($convert_fraction) { $ret .= $this->_sep . trim($this->_toWords($fraction)); } else {