Improve german support (#222)

* german: fix case in currency names

Also, add more tests for german language.

* german: default to amount of euros, not cents

If a non-float number is provided, interpret it as a quantity in euros,
not cents.

* german: handle "ein Euro" vs "eins Euro" exception

* german: prefer "einhundert" over "hundert"

"hundert" is usually colloquial (even if widely used).

Exception: "eintausendste" and "hundertste" are special cases, here
"hundertste" and "tausendste" are usually preferred (see Duden).
This commit is contained in:
Hugo Lefeuvre
2018-11-16 22:19:36 +01:00
committed by Ernesto Rodriguez Ortiz
parent 4d8c93847c
commit 66a47e2423
2 changed files with 45 additions and 12 deletions

View File

@@ -78,7 +78,9 @@ class Num2Word_DE(Num2Word_EU):
ctext, cnum, ntext, nnum = curr + next
if cnum == 1:
if nnum < 10 ** 6:
if nnum == 100 or nnum == 1000:
return ("ein" + ntext, nnum)
elif nnum < 10 ** 6:
return next
ctext = "eine"
@@ -110,21 +112,35 @@ class Num2Word_DE(Num2Word_EU):
if outword.endswith(key):
outword = outword[:len(outword) - len(key)] + self.ords[key]
break
return outword + "te"
res = outword + "te"
# Exception: "hundertste" is usually preferred over "einhundertste"
if res == "eintausendste" or res == "einhundertste":
res = res.replace("ein", "", 1)
return res
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"
hightxt = "Euro"
lowtxt = "Cent"
if old:
hightxt = "mark"
lowtxt = "pfennig/e"
hightxt = "Mark"
lowtxt = "Pfennig/e"
return self.to_splitnum(val, hightxt=hightxt, lowtxt=lowtxt,
jointxt="und", longval=longval)
cents = int(round(val*100))
res = self.to_splitnum(cents, hightxt=hightxt, lowtxt=lowtxt,
jointxt="und", longval=longval)
# Handle exception, in german is "ein Euro" and not "eins Euro"
if res.startswith("eins "):
res = res.replace("eins ", "ein ", 1)
return res
def to_year(self, val, longval=True):
if not (val // 100) % 10: