Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Ukrainian support and minor fixes in CZ, KZ, LT, LV, PL, RU, SR languages #400

Merged
merged 10 commits into from
Jun 30, 2021
6 changes: 5 additions & 1 deletion num2words/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def pluralize(self, n, forms):
"""
raise NotImplementedError

def _money_verbose(self, number, currency):
return self.to_cardinal(number)

def _cents_verbose(self, number, currency):
return self.to_cardinal(number)

Expand Down Expand Up @@ -290,12 +293,13 @@ def to_currency(self, val, currency='EUR', cents=True, separator=',',
cr1 = prefix_currency(self.CURRENCY_ADJECTIVES[currency], cr1)

minus_str = "%s " % self.negword if is_negative else ""
money_str = self._money_verbose(left, currency)
cents_str = self._cents_verbose(right, currency) \
if cents else self._cents_terse(right, currency)

return u'%s%s %s%s %s %s' % (
minus_str,
self.to_cardinal(left),
money_str,
self.pluralize(left, cr1),
separator,
cents_str,
Expand Down
5 changes: 4 additions & 1 deletion num2words/lang_CZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ def to_cardinal(self, number):
n = str(number).replace(',', '.')
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
self._int2word(int(right)))
return u'%s %s %s' % (
self._int2word(int(left)),
self.pointword,
self._int2word(int(right))
decimal_part
)
else:
return self._int2word(int(n))
Expand Down
3 changes: 2 additions & 1 deletion num2words/lang_KZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ def to_cardinal(self, number):
n = str(number).replace(',', '.')
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
return u'%s %s %s' % (
self._int2word(int(left)),
self.pointword,
self._int2word(int(right))
(ZERO + ' ') * leading_zero_count + self._int2word(int(right))
mromdhane marked this conversation as resolved.
Show resolved Hide resolved
)
else:
return self._int2word(int(n))
Expand Down
5 changes: 4 additions & 1 deletion num2words/lang_LT.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ def to_cardinal(self, number):
base_str, n = self.parse_minus(n)
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
self._int2word(int(right)))
return '%s%s %s %s' % (
base_str,
self._int2word(int(left)),
self.pointword,
self._int2word(int(right))
decimal_part
)
else:
return "%s%s" % (base_str, self._int2word(int(n)))
Expand Down
5 changes: 4 additions & 1 deletion num2words/lang_LV.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ def to_cardinal(self, number):
base_str, n = self.parse_minus(n)
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
self._int2word(int(right)))
return '%s%s %s %s' % (
base_str,
self._int2word(int(left)),
self.pointword,
self._int2word(int(right))
decimal_part
)
else:
return "%s%s" % (base_str, self._int2word(int(n)))
Expand Down
5 changes: 4 additions & 1 deletion num2words/lang_PL.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ def to_cardinal(self, number):
n = str(number).replace(',', '.')
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
self._int2word(int(right)))
return u'%s %s %s' % (
self._int2word(int(left)),
self.pointword,
self._int2word(int(right))
decimal_part
)
else:
return self._int2word(int(n))
Expand Down
10 changes: 8 additions & 2 deletions num2words/lang_RU.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ def to_cardinal(self, number):
n = str(number).replace(',', '.')
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
self._int2word(int(right)))
return u'%s %s %s' % (
self._int2word(int(left)),
self.pointword,
self._int2word(int(right))
decimal_part
)
else:
return self._int2word(int(n))
Expand Down Expand Up @@ -201,8 +204,11 @@ def to_ordinal(self, number):
outwords[-1] = self.title(lastword)
return " ".join(outwords).strip()

def _money_verbose(self, number, currency):
return self._int2word(number, currency == 'UAH')

def _cents_verbose(self, number, currency):
return self._int2word(number, currency == 'RUB')
return self._int2word(number, currency in ('UAH', 'RUB'))

def _int2word(self, n, feminine=False):
if n < 0:
Expand Down
5 changes: 4 additions & 1 deletion num2words/lang_SR.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ def to_cardinal(self, number, feminine=False):
n = str(number).replace(',', '.')
if '.' in n:
left, right = n.split('.')
leading_zero_count = len(right) - len(right.lstrip('0'))
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
self._int2word(int(right), feminine))
return u'%s %s %s' % (
self._int2word(int(left), feminine),
self.pointword,
self._int2word(int(right), feminine)
decimal_part
)
else:
return self._int2word(int(n), feminine)
Expand Down
Loading