From 321dfd3bca7010c5ec00afc5688a21c35d570485 Mon Sep 17 00:00:00 2001 From: dazre Date: Thu, 30 Mar 2017 15:33:37 +0300 Subject: [PATCH 1/3] remove middle THOUSANDS in case of zero digits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Error: num2words(1000139, lang='ru') -> миллион *тысяч* сто тридцать девять Fix: num2words(1000139, lang='ru') -> миллион сто тридцать девять --- num2words/lang_RU.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/num2words/lang_RU.py b/num2words/lang_RU.py index 922a852..9e0ad5e 100644 --- a/num2words/lang_RU.py +++ b/num2words/lang_RU.py @@ -243,7 +243,7 @@ def int2word(n, feminine=False): ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES words.append(ones[n1][0]) - if i > 0: + if i > 0 and x != 0: words.append(pluralize(x, THOUSANDS[i])) return ' '.join(words) From ba8db2589808c1bb6f95596cfd2741c64da2f1ed Mon Sep 17 00:00:00 2001 From: dazre Date: Thu, 30 Mar 2017 15:37:42 +0300 Subject: [PATCH 2/3] add leading Ones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's more more correctly in Russian: num2words(1135, lang='ru') -> одна тысяча сто тридцать пять num2words(1000139, lang='ru') -> один миллион сто тридцать девять --- num2words/lang_RU.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/num2words/lang_RU.py b/num2words/lang_RU.py index 9e0ad5e..846d8db 100644 --- a/num2words/lang_RU.py +++ b/num2words/lang_RU.py @@ -239,7 +239,7 @@ def int2word(n, feminine=False): if n2 == 1: words.append(TENS[n1][0]) - elif n1 > 0 and not (i > 0 and x == 1): + elif n1 > 0: ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES words.append(ones[n1][0]) From e226cf7d736bbd1aa96dbbf27f34730af59a127b Mon Sep 17 00:00:00 2001 From: dazre Date: Tue, 4 Apr 2017 17:32:55 +0300 Subject: [PATCH 3/3] add test --- tests/test_ru.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/test_ru.py diff --git a/tests/test_ru.py b/tests/test_ru.py new file mode 100644 index 0000000..d4f4087 --- /dev/null +++ b/tests/test_ru.py @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +from unittest import TestCase + +from num2words import num2words + +class Num2WordsRUTest(TestCase): + + def test_cardinal(self): + self.assertEqual(num2words(5, lang='ru'), u"пять") + self.assertEqual(num2words(15, lang='ru'), u"пятнадцать") + self.assertEqual(num2words(154, lang='ru'), u"сто пятьдесят четыре") + self.assertEqual(num2words(1135, lang='ru'), u"одна тысяча сто тридцать пять") + self.assertEqual(num2words(418531, lang='ru'), u"четыреста восемнадцать тысяч пятьсот тридцать один") + self.assertEqual(num2words(1000139, lang='ru'), u"один миллион сто тридцать девять") + + def test_floating_point(self): + self.assertEqual(num2words(5.2, lang='ru'), u"пять запятая два") + self.assertEqual(num2words(561.42, lang='ru'), u"пятьсот шестьдесят один запятая сорок два")