Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
akki2825 committed Apr 14, 2019
2 parents 8e2677a + f4b2bac commit ebb04b2
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 161 deletions.
1 change: 1 addition & 0 deletions .coverage

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .eggs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins.

This directory caches those eggs to prevent repeated downloads.

However, it is safe to delete this directory.

Binary file added .eggs/delegator.py-0.1.1-py3.6.egg
Binary file not shown.
41 changes: 6 additions & 35 deletions num2words/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,12 @@

from __future__ import unicode_literals

from . import lang_AR
from . import lang_CZ
from . import lang_EN
from . import lang_EN_IN
from . import lang_FR
from . import lang_FR_CH
from . import lang_FR_BE
from . import lang_FR_DZ
from . import lang_DE
from . import lang_ES
from . import lang_FI
from . import lang_LT
from . import lang_LV
from . import lang_PL
from . import lang_RO
from . import lang_RU
from . import lang_ID
from . import lang_JA
from . import lang_NO
from . import lang_DK
from . import lang_PT
from . import lang_PT_BR
from . import lang_HE
from . import lang_IT
from . import lang_ES_VE
from . import lang_ES_CO
from . import lang_VI
from . import lang_TR
from . import lang_NL
from . import lang_UK
from . import lang_SL
from . import lang_SR
from . import lang_TH
from . import lang_KO
from . import lang_KN
from . import (lang_AR, lang_CZ, lang_DE, lang_DK, lang_EN, lang_EN_IN,
lang_ES, lang_ES_CO, lang_ES_VE, lang_FI, lang_FR, lang_FR_BE,
lang_FR_CH, lang_FR_DZ, lang_HE, lang_ID, lang_IT, lang_JA,
lang_KO, lang_KN, lang_LT, lang_LV, lang_NL, lang_NO, lang_PL, lang_PT,
lang_PT_BR, lang_RO, lang_RU, lang_SL, lang_SR, lang_TH,
lang_TR, lang_UK, lang_VI)

CONVERTER_CLASSES = {
'ar': lang_AR.Num2Word_AR(),
Expand Down
29 changes: 14 additions & 15 deletions num2words/lang_DE.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@


class Num2Word_DE(Num2Word_EU):
CURRENCY_FORMS = {
'EUR': (('Euro', 'Euro'), ('Cent', 'Cent')),
'GBP': (('Pfund', 'Pfund'), ('Penny', 'Pence')),
'USD': (('Dollar', 'Dollar'), ('Cent', 'Cent')),
'CNY': (('Yuan', 'Yuan'), ('Jiao', 'Fen')),
'DEM': (('Mark', 'Mark'), ('Pfennig', 'Pfennig')),
}

GIGA_SUFFIX = "illiarde"
MEGA_SUFFIX = "illion"

Expand Down Expand Up @@ -134,22 +142,13 @@ def to_ordinal_num(self, value):
self.verify_ordinal(value)
return str(value) + "."

def to_currency(self, val, longval=True, old=False):
hightxt = "Euro"
lowtxt = "Cent"
if old:
hightxt = "Mark"
lowtxt = "Pfennig/e"

cents = int(round(val*100))
res = self.to_splitnum(cents, hightxt=hightxt, lowtxt=lowtxt,
jointxt="und", longval=longval)

def to_currency(self, val, currency='EUR', cents=True, separator=' und',
adjective=False):
result = super(Num2Word_DE, self).to_currency(
val, currency=currency, cents=cents, separator=separator,
adjective=adjective)
# Handle exception, in german is "ein Euro" and not "eins Euro"
if res.startswith("eins "):
res = res.replace("eins ", "ein ", 1)

return res
return result.replace("eins ", "ein ")

def to_year(self, val, longval=True):
if not (val // 100) % 10:
Expand Down
2 changes: 2 additions & 0 deletions num2words/lang_EU.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Num2Word_EU(Num2Word_Base):
'PLN': (('zloty', 'zlotys', 'zlotu'), ('grosz', 'groszy')),
'MXN': (('peso', 'pesos'), GENERIC_CENTS),
'RON': (('leu', 'lei'), ('ban', 'bani')),
'INR': (('rupee', 'rupees'), ('paisa', 'paise'))
}

CURRENCY_ADJECTIVES = {
Expand All @@ -53,6 +54,7 @@ class Num2Word_EU(Num2Word_Base):
'NOK': 'Norwegian',
'MXN': 'Mexican',
'RON': 'Romanian',
'INR': 'Indian',
}

GIGA_SUFFIX = "illiard"
Expand Down
21 changes: 14 additions & 7 deletions num2words/lang_FR.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@


class Num2Word_FR(Num2Word_EU):
CURRENCY_FORMS = {
'EUR': (('euro', 'euros'), ('centime', 'centimes')),
'USD': (('dollar', 'dollars'), ('cent', 'cents')),
'FRF': (('franc', 'francs'), ('centime', 'centimes')),
'GBP': (('livre', 'livres'), ('penny', 'pence')),
'CNY': (('yuan', 'yuans'), ('fen', 'jiaos')),
}

def setup(self):
Num2Word_EU.setup(self)

Expand Down Expand Up @@ -92,10 +100,9 @@ def to_ordinal_num(self, value):
out += "er" if value == 1 else "me"
return out

def to_currency(self, val, longval=True, old=False):
hightxt = "euro/s"
if old:
hightxt = "franc/s"
cents = int(round(val*100))
return self.to_splitnum(cents, hightxt=hightxt, lowtxt="centime/s",
divisor=100, jointxt="et", longval=longval)
def to_currency(self, val, currency='EUR', cents=True, separator=' et',
adjective=False):
result = super(Num2Word_FR, self).to_currency(
val, currency=currency, cents=cents, separator=separator,
adjective=adjective)
return result
15 changes: 10 additions & 5 deletions num2words/lang_FR_DZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@


class Num2Word_FR_DZ(Num2Word_FR):
def to_currency(self, val, longval=True, cents=True, jointxt="virgule"):
return self.to_splitnum(
val, hightxt="dinard/s", lowtxt="centime/s", divisor=1,
jointxt=jointxt, longval=longval, cents=cents
)
CURRENCY_FORMS = {
'DIN': (('dinard', 'dinards'), ('centime', 'centimes')),
}

def to_currency(self, val, currency='DIN', cents=True, separator=' et',
adjective=False):
result = super(Num2Word_FR, self).to_currency(
val, currency=currency, cents=cents, separator=separator,
adjective=adjective)
return result
5 changes: 4 additions & 1 deletion num2words/lang_NL.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

class Num2Word_NL(Num2Word_EU):
CURRENCY_FORMS = {
'EUR': (('euro', 'euros'), ('cent', 'cents')),
'EUR': (('euro', 'euro'), ('cent', 'cent')),
'GBP': (('pond', 'pond'), ('penny', 'pence')),
'USD': (('dollar', 'dollar'), ('cent', 'cent')),
'CNY': (('yuan', 'yuan'), ('jiao', 'fen')),
}

GIGA_SUFFIX = "iljard"
Expand Down
40 changes: 34 additions & 6 deletions num2words/lang_SL.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@


class Num2Word_SL(Num2Word_EU):
GIGA_SUFFIX = "iljard"
MEGA_SUFFIX = "iljon"
GIGA_SUFFIX = "ilijard"
MEGA_SUFFIX = "ilijon"

def setup(self):
super(Num2Word_SL, self).setup()
Expand All @@ -36,7 +36,7 @@ def setup(self):

self.mid_numwords = [(1000, "tisoč"), (900, "devetsto"),
(800, "osemsto"), (700, "sedemsto"),
(600, "šesto"), (500, "petsto"),
(600, "šeststo"), (500, "petsto"),
(400, "štiristo"), (300, "tristo"),
(200, "dvesto"), (100, "sto"),
(90, "devetdeset"), (80, "osemdeset"),
Expand All @@ -57,16 +57,31 @@ def setup(self):
"osem": "osm",
"sto": "stot",
"tisoč": "tisoč",
"miljon": "miljont"
"milijon": "milijont"
}
self.ordflag = False

def merge(self, curr, next):
ctext, cnum, ntext, nnum = curr + next

if ctext == "dve" and not self.ordflag:
if ctext.endswith("dve") and self.ordflag and nnum <= 1000000:
ctext = ctext[:len(ctext)-1] + "a"

if ctext == "dve" and not self.ordflag and nnum < 1000000000:
ctext = "dva"

if (ctext.endswith("tri") or ctext.endswith("štiri")) and\
nnum == 1000000 and not self.ordflag:
if ctext.endswith("štiri"):
ctext = ctext[:-1]
ctext = ctext + "je"

if cnum >= 20 and cnum < 100 and nnum == 2:
ntext = "dva"

if ctext.endswith("ena") and nnum >= 1000:
ctext = ctext[0:-1]

if cnum == 1:
if nnum < 10**6 or self.ordflag:
return next
Expand All @@ -89,15 +104,28 @@ def merge(self, curr, next):
elif not ntext.endswith("d"):
ntext += "i"

elif ctext.endswith("en"):
if ntext.endswith("d") or ntext.endswith("n"):
ntext += ""

elif ctext.endswith("dve") and ntext.endswith("n"):
ctext = ctext[:-1] + "a"
ntext += "a"

elif ctext.endswith("je") and ntext.endswith("n"):
ntext += "i"

else:
if ntext.endswith("d"):
ntext += "a"
elif ntext.endswith("n"):
ntext += ""
elif ntext.endswith("d"):
ntext += "e"
else:
ntext += "ov"

if nnum >= 10**2 and self.ordflag is False:
if nnum >= 10**2 and self.ordflag is False and ctext:
ctext += " "

val = cnum * nnum
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest

import delegator

import num2words


Expand Down
90 changes: 67 additions & 23 deletions tests/test_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,46 @@

from num2words import num2words

TEST_CASES_TO_CURRENCY_EUR = (
(1.00, 'ein Euro und null Cent'),
(2.01, 'zwei Euro und ein Cent'),
(8.10, 'acht Euro und zehn Cent'),
(12.26, 'zwölf Euro und sechsundzwanzig Cent'),
(21.29, 'einundzwanzig Euro und neunundzwanzig Cent'),
(81.25, 'einundachtzig Euro und fünfundzwanzig Cent'),
(100.00, 'einhundert Euro und null Cent'),
)

TEST_CASES_TO_CURRENCY_USD = (
(1.00, 'ein Dollar und null Cent'),
(2.01, 'zwei Dollar und ein Cent'),
(8.10, 'acht Dollar und zehn Cent'),
(12.26, 'zwölf Dollar und sechsundzwanzig Cent'),
(21.29, 'einundzwanzig Dollar und neunundzwanzig Cent'),
(81.25, 'einundachtzig Dollar und fünfundzwanzig Cent'),
(100.00, 'einhundert Dollar und null Cent'),
)

TEST_CASES_TO_CURRENCY_GBP = (
(1.00, 'ein Pfund und null Pence'),
(2.01, 'zwei Pfund und ein Penny'),
(8.10, 'acht Pfund und zehn Pence'),
(12.26, 'zwölf Pfund und sechsundzwanzig Pence'),
(21.29, 'einundzwanzig Pfund und neunundzwanzig Pence'),
(81.25, 'einundachtzig Pfund und fünfundzwanzig Pence'),
(100.00, 'einhundert Pfund und null Pence'),
)

TEST_CASES_TO_CURRENCY_DEM = (
(1.00, 'ein Mark und null Pfennig'),
(2.01, 'zwei Mark und ein Pfennig'),
(8.10, 'acht Mark und zehn Pfennig'),
(12.26, 'zwölf Mark und sechsundzwanzig Pfennig'),
(21.29, 'einundzwanzig Mark und neunundzwanzig Pfennig'),
(81.25, 'einundachtzig Mark und fünfundzwanzig Pfennig'),
(100.00, 'einhundert Mark und null Pfennig'),
)


class Num2WordsDETest(TestCase):

Expand Down Expand Up @@ -93,29 +133,33 @@ def test_ordinal_for_negative_numbers(self):
def test_ordinal_for_floating_numbers(self):
self.assertRaises(TypeError, num2words, 2.453, ordinal=True, lang='de')

def test_currency(self):
self.assertEqual(num2words(1, lang='de', to='currency'),
'ein Euro')
self.assertEqual(num2words(12, lang='de', to='currency'),
'zwölf Euro')
self.assertEqual(num2words(12.00, lang='de', to='currency'),
'zwölf Euro')
self.assertEqual(num2words(100.0, lang='de', to='currency'),
"einhundert Euro")
self.assertEqual(num2words(190, lang='de', to='currency'),
"einhundertneunzig Euro")
self.assertEqual(num2words(1.90, lang='de', to='currency'),
"ein Euro und neunzig Cent")
self.assertEqual(num2words(3.4, lang='de', to='currency'),
"drei Euro und vierzig Cent")
self.assertEqual(num2words(20.18, lang='de', to='currency'),
"zwanzig Euro und achtzehn Cent")
self.assertEqual(num2words(3.04, lang='de', to='currency'),
"drei Euro und vier Cent")

def test_old_currency(self):
self.assertEqual(num2words(12.00, to='currency', lang='de', old=True),
'zwölf Mark')
def test_currency_eur(self):
for test in TEST_CASES_TO_CURRENCY_EUR:
self.assertEqual(
num2words(test[0], lang='de', to='currency', currency='EUR'),
test[1]
)

def test_currency_usd(self):
for test in TEST_CASES_TO_CURRENCY_USD:
self.assertEqual(
num2words(test[0], lang='de', to='currency', currency='USD'),
test[1]
)

def test_currency_dem(self):
for test in TEST_CASES_TO_CURRENCY_DEM:
self.assertEqual(
num2words(test[0], lang='de', to='currency', currency='DEM'),
test[1]
)

def test_currency_gbp(self):
for test in TEST_CASES_TO_CURRENCY_GBP:
self.assertEqual(
num2words(test[0], lang='de', to='currency', currency='GBP'),
test[1]
)

def test_year(self):
self.assertEqual(num2words(2002, to='year', lang='de'),
Expand Down

0 comments on commit ebb04b2

Please sign in to comment.