Skip to content

Commit

Permalink
Improve Ukrainian support and minor fixes in CZ, KZ, LT, LV, PL, RU, …
Browse files Browse the repository at this point in the history
…SR languages (savoirfairelinux#400)

* Fix English char 'i' in Ukrainian words

* Fix the feminine currency processing for UAH in lang_UK.py

* Fix test_ua.py

* Fix the feminine currency processing for UAH in lang_RU.py

* Add tests for UAH in test_ru.py

* Add world currencies to lang_UK.py; Add test cases to test_uk.py for world currencies

* Fix incorrect handling of zeros after decimal point for CZ, KZ, LT, LV, PL, RU, SR and UK languages

* Add ukrainian ordinal numbers

* Fix too long lines of code

* Add test for negative cardinal number
  • Loading branch information
rostyslav80 authored and KommuSoft committed Aug 18, 2022
1 parent 79a9abf commit 6bf14be
Show file tree
Hide file tree
Showing 17 changed files with 4,189 additions and 153 deletions.
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))
)
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

0 comments on commit 6bf14be

Please sign in to comment.