diff --git a/num2words/lang_RU.py b/num2words/lang_RU.py index 10be86c1..6bc31ede 100644 --- a/num2words/lang_RU.py +++ b/num2words/lang_RU.py @@ -328,7 +328,11 @@ def setup(self): self.pointword_ord = make_ord_cases("цел", 1) def to_cardinal(self, number, case=D_CASE, plural=D_PLURAL, - gender=D_GENDER, animate=D_ANIMATE): + gender=D_GENDER, animate=D_ANIMATE, feminine=False): + # Backward compatibility + if feminine: + gender = 'f' + n = str(number).replace(',', '.') if '.' in n: left, right = n.split('.') @@ -368,7 +372,11 @@ def pluralize(self, n, forms): return forms[2] def to_ordinal(self, number, case=D_CASE, plural=D_PLURAL, gender=D_GENDER, - animate=D_ANIMATE): + animate=D_ANIMATE, feminine=False): + # Backward compatibility + if feminine: + gender = 'f' + self.verify_ordinal(number) n = str(number).replace(',', '.') return self._int2word(int(n), cardinal=False, case=case, plural=plural, @@ -384,12 +392,11 @@ def _cents_verbose(self, number, currency): return self._int2word(number, gender='f') return self._int2word(number, gender='m') - def _int2word(self, n, feminine=False, cardinal=True, case=D_CASE, + def _int2word(self, n, cardinal=True, case=D_CASE, plural=D_PLURAL, gender=D_GENDER, animate=D_ANIMATE): """ Main function :param n: number of items - :param feminine: not used (for backward compatibility) :param cardinal: True(cardinal), False(ordinal) :param case: 'n'(nominative), 'g'(genitive), 'd'(dative), 'a'(accusative),'i'(instrumental), 'p'(prepositional) @@ -398,10 +405,6 @@ def _int2word(self, n, feminine=False, cardinal=True, case=D_CASE, :param animate: True(animate), False(inanimate) :return text """ - # For backward compatibility - if feminine: - gender = 'f' - kwargs = {'case': case, 'plural': plural, 'gender': gender, 'animate': animate} @@ -436,7 +439,7 @@ def _int2word(self, n, feminine=False, cardinal=True, case=D_CASE, if i > 0: chunk_words.append( self.pluralize(x, get_thousands_elements(i, case))) - # ordinal, not joined like 'двухтысячный' + # ordinal, not joined (not like 'двухтысячный') elif not (ord_join and rightest_nonzero_chunk_i == i): chunk_words.extend( self.__chunk_ordinal(n3, n2, n1, i, **kwargs) @@ -447,14 +450,10 @@ def _int2word(self, n, feminine=False, cardinal=True, case=D_CASE, self.pluralize(x, get_thousands_elements(i, t_case))) # ordinal, joined else: - chunk_words.extend( - self.__chunk_ordinal_join(n3, n2, n1, i, **kwargs) + chunk_words.append( + self.__chunk_ordinal_joined(n3, n2, n1, **kwargs) + + get_mldir_value(THOUSANDS_ORD, i, **kwargs) ) - if i > 0: - chunk_words.append( - get_mldir_value(THOUSANDS_ORD, i, **kwargs)) - - chunk_words = [''.join(chunk_words)] words.extend(chunk_words) @@ -517,7 +516,7 @@ def __chunk_ordinal(self, hundreds, tens, ones, chunk_num, **kwargs): return words - def __chunk_ordinal_join(self, hundreds, tens, ones, chunk_num, **kwargs): + def __chunk_ordinal_joined(self, hundreds, tens, ones, **kwargs): words = [] if hundreds > 1: @@ -533,10 +532,8 @@ def __chunk_ordinal_join(self, hundreds, tens, ones, chunk_num, **kwargs): if tens == 1: words.append(get_mldir_value(TENS, ones, case='g')) elif ones > 0: - if chunk_num == 0: - w_ones = get_mldir_value(ONES_ORD, ones, **kwargs) # тысячный, миллионнный и т.д., двадцатиодномиллионный - elif chunk_num > 0 and ones == 1 and tens != 1: + if ones == 1 and tens != 1: if tens == 0 and hundreds == 0: w_ones = None else: @@ -547,4 +544,4 @@ def __chunk_ordinal_join(self, hundreds, tens, ones, chunk_num, **kwargs): if w_ones: words.append(w_ones) - return words + return ''.join(words) diff --git a/tests/test_ru.py b/tests/test_ru.py index 0ac0e60e..640cc833 100644 --- a/tests/test_ru.py +++ b/tests/test_ru.py @@ -519,3 +519,13 @@ def test_to_currency(self): 'одна тысяча двести тридцать четыре польских злотых, ' 'пятьдесят шесть грошей' ) + + def test_backward_compatibility(self): + self.assertEqual( + num2words(1, lang='ru', feminine=True), + 'одна' + ) + self.assertEqual( + num2words(1, lang='ru', to='ordinal', feminine=True), + 'первая' + )