Skip to content

Commit

Permalink
Using the new constants internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
jurchiks committed Dec 5, 2015
1 parent 6ba3f6b commit 0c96fd5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 75 deletions.
19 changes: 12 additions & 7 deletions src/Speller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ abstract class Speller
const CURRENCY_US_DOLLAR = 'USD';

private static $languages = array(
'en' => languages\English::class,
'es' => languages\Spanish::class,
'et' => languages\Estonian::class,
'lt' => languages\Lithuanian::class,
'lv' => languages\Latvian::class,
'ru' => languages\Russian::class,
self::LANGUAGE_ENGLISH => languages\English::class,
self::LANGUAGE_ESTONIAN => languages\Estonian::class,
self::LANGUAGE_LATVIAN => languages\Latvian::class,
self::LANGUAGE_LITHUANIAN => languages\Lithuanian::class,
self::LANGUAGE_RUSSIAN => languages\Russian::class,
self::LANGUAGE_SPANISH => languages\Spanish::class,
);

private static $currencies = array(
'EUR', 'LTL', 'LVL', 'RUR', 'USD', 'GBP',
self::CURRENCY_EURO,
self::CURRENCY_BRITISH_POUND,
self::CURRENCY_LATVIAN_LAT,
self::CURRENCY_LITHUANIAN_LIT,
self::CURRENCY_RUSSIAN_ROUBLE,
self::CURRENCY_US_DOLLAR,
);

protected $minus;
Expand Down
22 changes: 11 additions & 11 deletions src/languages/English.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,30 @@ protected function spellExponent($type, $number, $currency)
protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
'EUR' => array(
self::CURRENCY_EURO => array(
'whole' => array('euro', 'euro'),
'decimal' => array('cent', 'cents'),
),
'LTL' => array(
'whole' => array('litas', 'litai'),
'decimal' => array('centas', 'centai'),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('pound', 'pounds'),
'decimal' => array('penny', 'pennies'),
),
'LVL' => array(
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('lat', 'lats'),
'decimal' => array('santim', 'santims'),
),
'RUR' => array(
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('litas', 'litai'),
'decimal' => array('centas', 'centai'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('ruble', 'rubles'),
'decimal' => array('kopek', 'kopeks'),
),
'USD' => array(
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dollar', 'dollars'),
'decimal' => array('cent', 'cents'),
),
'GBP' => array(
'whole' => array('pound', 'pounds'),
'decimal' => array('penny', 'pennies'),
),
);

if (!isset($names[$currency]))
Expand Down
22 changes: 11 additions & 11 deletions src/languages/Estonian.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,30 @@ protected function spellExponent($type, $number, $currency)
protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
'EUR' => array(
self::CURRENCY_EURO => array(
'whole' => array('euro', 'eurot'),
'decimal' => array('sent', 'senti'),
),
'LTL' => array(
'whole' => array('litt', 'litti'),
'decimal' => array('sent', 'senti'),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('nael', 'naela'),
'decimal' => array('penn', 'penni'),
),
'LVL' => array(
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('latt', 'latti'),
'decimal' => array('santiim', 'santiimi'),
),
'RUR' => array(
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('litt', 'litti'),
'decimal' => array('sent', 'senti'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('rubla', 'rubla'),
'decimal' => array('kopikas', 'kopikat'),
),
'USD' => array(
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dollar', 'dollarit'),
'decimal' => array('sent', 'senti'),
),
'GBP' => array(
'whole' => array('nael', 'naela'),
'decimal' => array('penn', 'penni'),
),
);

if (!isset($names[$currency]))
Expand Down
24 changes: 12 additions & 12 deletions src/languages/Latvian.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function spellSingle($digit, $isDecimalPart, $currency)
9 => 'deviņas',
);

if ($isDecimalPart && ($currency === 'RUR'))
if ($isDecimalPart && ($currency === self::CURRENCY_RUSSIAN_ROUBLE))
{
// russian kopek nouns are feminine gender in Latvian
return $singlesFeminine[intval($digit)];
Expand Down Expand Up @@ -146,30 +146,30 @@ protected function spellExponent($type, $number, $currency)
protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
'EUR' => array(
self::CURRENCY_EURO => array(
'whole' => array('eiro', 'eiro', 'eiro'),
'decimal' => array('cents', 'centi', 'centu'),
),
'LTL' => array(
'whole' => array('lits', 'liti', 'litu'),
'decimal' => array('cents', 'centi', 'centu'),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('mārciņa', 'mārciņas', 'mārciņu'),
'decimal' => array('penijs', 'peniji', 'peniju'),
),
'LVL' => array(
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('lats', 'lati', 'latu'),
'decimal' => array('santīms', 'santīmi', 'santīmu'),
),
'RUR' => array(
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('lits', 'liti', 'litu'),
'decimal' => array('cents', 'centi', 'centu'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('rublis', 'rubļi', 'rubļu'),
'decimal' => array('kapeika', 'kapeikas', 'kapeiku'),
),
'USD' => array(
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dolārs', 'dolāri', 'dolāru'),
'decimal' => array('cents', 'centi', 'centu'),
),
'GBP' => array(
'whole' => array('mārciņa', 'mārciņas', 'mārciņu'),
'decimal' => array('penijs', 'peniji', 'peniju'),
),
);

if (!isset($names[$currency]))
Expand Down
22 changes: 11 additions & 11 deletions src/languages/Lithuanian.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,30 @@ protected function spellExponent($type, $number, $currency)
protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
'EUR' => array(
self::CURRENCY_EURO => array(
'whole' => array('euras', 'eurai', 'eurų'),
'decimal' => array('centas', 'centai', 'centų'),
),
'LTL' => array(
'whole' => array('litas', 'litai', 'litų'),
'decimal' => array('centas', 'centai', 'centų'),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('svaras', 'svarai', 'svarų'),
'decimal' => array('pensas', 'pensai', 'pensų'),
),
'LVL' => array(
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('latas', 'latai', 'latų'),
'decimal' => array('santimas', 'santimai', 'santimų'),
),
'RUR' => array(
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('litas', 'litai', 'litų'),
'decimal' => array('centas', 'centai', 'centų'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('rublis', 'rubliai', 'rublių'),
'decimal' => array('kapeika', 'kapeikos', 'kapeikų'),
),
'USD' => array(
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dolaras', 'dolarai', 'dolarų'),
'decimal' => array('centas', 'centai', 'centų'),
),
'GBP' => array(
'whole' => array('svaras', 'svarai', 'svarų'),
'decimal' => array('pensas', 'pensai', 'pensų'),
),
);

if (!isset($names[$currency]))
Expand Down
24 changes: 12 additions & 12 deletions src/languages/Russian.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function spellSingle($digit, $groupOfThrees, $isDecimalPart, $currency)
);

if (($groupOfThrees === 2) // thousands
|| ($isDecimalPart && ($currency === 'RUR'))) // russian kopeks
|| ($isDecimalPart && ($currency === self::CURRENCY_RUSSIAN_ROUBLE))) // russian kopeks
{
return $singlesFeminine[intval($digit)];
}
Expand Down Expand Up @@ -158,30 +158,30 @@ protected function spellExponent($type, $number, $currency)
protected function getCurrencyName($type, $number, $currency)
{
static $names = array(
'EUR' => array(
self::CURRENCY_EURO => array(
'whole' => array('евро', 'евро', 'евро'),
'decimal' => array('цент', 'цента', 'центов'),
),
'LTL' => array(
'whole' => array('лит', 'лита', 'литов'),
'decimal' => array('цент', 'цента', 'центов'),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('фунт', 'фунта', 'фунтов'),
'decimal' => array('пенни', 'пенса', 'пенсов'),
),
'LVL' => array(
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('лат', 'лата', 'латов'),
'decimal' => array('сантим', 'сантима', 'сантимов'),
),
'RUR' => array(
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('лит', 'лита', 'литов'),
'decimal' => array('цент', 'цента', 'центов'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('рубль', 'рубля', 'рублей'),
'decimal' => array('копейка', 'копейки', 'копеек'),
),
'USD' => array(
self::CURRENCY_US_DOLLAR => array(
'whole' => array('доллар', 'доллара', 'долларов'),
'decimal' => array('цент', 'цента', 'центов'),
),
'GBP' => array(
'whole' => array('фунт', 'фунта', 'фунтов'),
'decimal' => array('пенни', 'пенса', 'пенсов'),
),
);

if (!isset($names[$currency]))
Expand Down
22 changes: 11 additions & 11 deletions src/languages/Spanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,30 @@ protected function getCurrencyName($type, $number, $currency)
{
// TODO some of these spellings are extremely hard to find and are probably incorrect
static $names = array(
'EUR' => array(
self::CURRENCY_EURO => array(
'whole' => array('euro', 'euros'),
'decimal' => array('centime', 'centimes'),
),
'LTL' => array(
'whole' => array('litas', 'litas'),
'decimal' => array('cent', 'cents'),
self::CURRENCY_BRITISH_POUND => array(
'whole' => array('libra esterlina', 'libras esterlinas'),
'decimal' => array('penique', 'peniques'),
),
'LVL' => array(
self::CURRENCY_LATVIAN_LAT => array(
'whole' => array('lat', 'lats'),
'decimal' => array('sentim', 'sentims'),
),
'RUR' => array(
self::CURRENCY_LITHUANIAN_LIT => array(
'whole' => array('litas', 'litas'),
'decimal' => array('cent', 'cents'),
),
self::CURRENCY_RUSSIAN_ROUBLE => array(
'whole' => array('rublo ruso', 'rublos rusos'),
'decimal' => array('kopek', 'kopeks'),
),
'USD' => array(
self::CURRENCY_US_DOLLAR => array(
'whole' => array('dólar estadounidense', 'dólares estadounidenses'),
'decimal' => array('centavo', 'centavos'),
),
'GBP' => array(
'whole' => array('libra esterlina', 'libras esterlinas'),
'decimal' => array('penique', 'peniques'),
),
);

if (!isset($names[$currency]))
Expand Down

0 comments on commit 0c96fd5

Please sign in to comment.