mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Fixing currency functions for german and french. Adding Currency_Forms for DE, FR and NL. (#247)
* Fix currency function for French. Adding Currency_Forms. * Fix currency function for German. Adding Currency_Forms. * Move FR_DZ to new currency functions, too. * Fix tests * Add more currency options for dutch. * Add more tests for German, Dutch and French currencies.
This commit is contained in:
committed by
Ernesto Rodriguez Ortiz
parent
18194b52ef
commit
a869745813
@@ -23,6 +23,14 @@ from .lang_EU import Num2Word_EU
|
||||
|
||||
|
||||
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"
|
||||
|
||||
@@ -134,22 +142,13 @@ class Num2Word_DE(Num2Word_EU):
|
||||
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:
|
||||
|
||||
@@ -21,6 +21,14 @@ from .lang_EU import Num2Word_EU
|
||||
|
||||
|
||||
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)
|
||||
|
||||
@@ -92,10 +100,9 @@ class Num2Word_FR(Num2Word_EU):
|
||||
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
|
||||
|
||||
@@ -21,8 +21,13 @@ from .lang_FR import Num2Word_FR
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -22,7 +22,10 @@ from .lang_EU import Num2Word_EU
|
||||
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user