diff --git a/README.rst b/README.rst index 24d6867d..2531f84b 100644 --- a/README.rst +++ b/README.rst @@ -73,15 +73,15 @@ Besides the numerical argument, there are two main optional arguments, ``to:`` a * ``year`` * ``currency`` -**lang:** The language in which to convert the number. Supported values are: +**lang:** The language in which to convert the number, in the ISO 639-1 code format. Supported values are: * ``en`` (English, default) * ``am`` (Amharic) * ``ar`` (Arabic) * ``az`` (Azerbaijani) -* ``cz`` (Czech) +* ``cs`` (Czech) +* ``da`` (Danish) * ``de`` (German) -* ``dk`` (Danish) * ``en_GB`` (English - Great Britain) * ``en_IN`` (English - India) * ``en_NG`` (English - Nigeria) @@ -102,9 +102,9 @@ Besides the numerical argument, there are two main optional arguments, ``to:`` a * ``is`` (Icelandic) * ``it`` (Italian) * ``ja`` (Japanese) +* ``kk`` (Kazakh) * ``kn`` (Kannada) * ``ko`` (Korean) -* ``kz`` (Kazakh) * ``lt`` (Lithuanian) * ``lv`` (Latvian) * ``no`` (Norwegian) diff --git a/bin/num2words b/bin/num2words index 06ff0443..8f87533d 100755 --- a/bin/num2words +++ b/bin/num2words @@ -50,9 +50,12 @@ Examples: """ from __future__ import print_function, unicode_literals + import os import sys + from docopt import docopt + import num2words __version__ = "0.5.12" diff --git a/num2words/__init__.py b/num2words/__init__.py index 0942928f..b4a81a36 100644 --- a/num2words/__init__.py +++ b/num2words/__init__.py @@ -17,70 +17,70 @@ from __future__ import unicode_literals -from . import (lang_AM, lang_AR, lang_AZ, lang_CZ, lang_DE, lang_DK, lang_EN, +from . import (lang_AM, lang_AR, lang_AZ, lang_CS, lang_DA, lang_DE, lang_EN, lang_EN_IN, lang_EN_NG, lang_EO, lang_ES, lang_ES_CO, lang_ES_GT, lang_ES_NI, lang_ES_VE, lang_FA, lang_FI, lang_FR, lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE, lang_HU, lang_ID, - lang_IS, lang_IT, lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT, + lang_IS, lang_IT, lang_JA, lang_KK, lang_KN, lang_KO, lang_LT, lang_LV, lang_NL, lang_NO, lang_PL, lang_PT, lang_PT_BR, lang_RO, lang_RU, lang_SL, lang_SR, lang_SV, lang_TE, lang_TG, lang_TH, lang_TR, lang_UK, lang_VI) CONVERTER_CLASSES = { - 'am': lang_AM.Num2Word_AM(), - 'ar': lang_AR.Num2Word_AR(), - 'az': lang_AZ.Num2Word_AZ(), - 'cz': lang_CZ.Num2Word_CZ(), - 'en': lang_EN.Num2Word_EN(), - 'en_IN': lang_EN_IN.Num2Word_EN_IN(), - 'en_NG': lang_EN_NG.Num2Word_EN_NG(), - 'fa': lang_FA.Num2Word_FA(), - 'fr': lang_FR.Num2Word_FR(), - 'fr_CH': lang_FR_CH.Num2Word_FR_CH(), - 'fr_BE': lang_FR_BE.Num2Word_FR_BE(), - 'fr_DZ': lang_FR_DZ.Num2Word_FR_DZ(), - 'de': lang_DE.Num2Word_DE(), - 'fi': lang_FI.Num2Word_FI(), - 'eo': lang_EO.Num2Word_EO(), - 'es': lang_ES.Num2Word_ES(), - 'es_CO': lang_ES_CO.Num2Word_ES_CO(), - 'es_GT': lang_ES_GT.Num2Word_ES_GT(), - 'es_NI': lang_ES_NI.Num2Word_ES_NI(), - 'es_VE': lang_ES_VE.Num2Word_ES_VE(), - 'id': lang_ID.Num2Word_ID(), - 'ja': lang_JA.Num2Word_JA(), - 'kn': lang_KN.Num2Word_KN(), - 'ko': lang_KO.Num2Word_KO(), - 'kz': lang_KZ.Num2Word_KZ(), - 'lt': lang_LT.Num2Word_LT(), - 'lv': lang_LV.Num2Word_LV(), - 'pl': lang_PL.Num2Word_PL(), - 'ro': lang_RO.Num2Word_RO(), - 'ru': lang_RU.Num2Word_RU(), - 'sl': lang_SL.Num2Word_SL(), - 'sr': lang_SR.Num2Word_SR(), - 'sv': lang_SV.Num2Word_SV(), - 'no': lang_NO.Num2Word_NO(), - 'dk': lang_DK.Num2Word_DK(), - 'pt': lang_PT.Num2Word_PT(), - 'pt_BR': lang_PT_BR.Num2Word_PT_BR(), - 'he': lang_HE.Num2Word_HE(), - 'it': lang_IT.Num2Word_IT(), - 'vi': lang_VI.Num2Word_VI(), - 'tg': lang_TG.Num2Word_TG(), - 'th': lang_TH.Num2Word_TH(), - 'tr': lang_TR.Num2Word_TR(), - 'nl': lang_NL.Num2Word_NL(), - 'uk': lang_UK.Num2Word_UK(), - 'te': lang_TE.Num2Word_TE(), - 'hu': lang_HU.Num2Word_HU(), - 'is': lang_IS.Num2Word_IS() + "am": lang_AM.Num2Word_AM(), + "ar": lang_AR.Num2Word_AR(), + "az": lang_AZ.Num2Word_AZ(), + "cs": lang_CS.Num2Word_CS(), + "en": lang_EN.Num2Word_EN(), + "en_IN": lang_EN_IN.Num2Word_EN_IN(), + "en_NG": lang_EN_NG.Num2Word_EN_NG(), + "fa": lang_FA.Num2Word_FA(), + "fr": lang_FR.Num2Word_FR(), + "fr_CH": lang_FR_CH.Num2Word_FR_CH(), + "fr_BE": lang_FR_BE.Num2Word_FR_BE(), + "fr_DZ": lang_FR_DZ.Num2Word_FR_DZ(), + "de": lang_DE.Num2Word_DE(), + "fi": lang_FI.Num2Word_FI(), + "eo": lang_EO.Num2Word_EO(), + "es": lang_ES.Num2Word_ES(), + "es_CO": lang_ES_CO.Num2Word_ES_CO(), + "es_GT": lang_ES_GT.Num2Word_ES_GT(), + "es_NI": lang_ES_NI.Num2Word_ES_NI(), + "es_VE": lang_ES_VE.Num2Word_ES_VE(), + "id": lang_ID.Num2Word_ID(), + "ja": lang_JA.Num2Word_JA(), + "kn": lang_KN.Num2Word_KN(), + "ko": lang_KO.Num2Word_KO(), + "kk": lang_KK.Num2Word_KK(), + "lt": lang_LT.Num2Word_LT(), + "lv": lang_LV.Num2Word_LV(), + "pl": lang_PL.Num2Word_PL(), + "ro": lang_RO.Num2Word_RO(), + "ru": lang_RU.Num2Word_RU(), + "sl": lang_SL.Num2Word_SL(), + "sr": lang_SR.Num2Word_SR(), + "sv": lang_SV.Num2Word_SV(), + "no": lang_NO.Num2Word_NO(), + "da": lang_DA.Num2Word_DA(), + "pt": lang_PT.Num2Word_PT(), + "pt_BR": lang_PT_BR.Num2Word_PT_BR(), + "he": lang_HE.Num2Word_HE(), + "it": lang_IT.Num2Word_IT(), + "vi": lang_VI.Num2Word_VI(), + "tg": lang_TG.Num2Word_TG(), + "th": lang_TH.Num2Word_TH(), + "tr": lang_TR.Num2Word_TR(), + "nl": lang_NL.Num2Word_NL(), + "uk": lang_UK.Num2Word_UK(), + "te": lang_TE.Num2Word_TE(), + "hu": lang_HU.Num2Word_HU(), + "is": lang_IS.Num2Word_IS(), } -CONVERTES_TYPES = ['cardinal', 'ordinal', 'ordinal_num', 'year', 'currency'] +CONVERTES_TYPES = ["cardinal", "ordinal", "ordinal_num", "year", "currency"] -def num2words(number, ordinal=False, lang='en', to='cardinal', **kwargs): +def num2words(number, ordinal=False, lang="en", to="cardinal", **kwargs): # We try the full language first if lang not in CONVERTER_CLASSES: # ... and then try only the first 2 letters @@ -94,9 +94,9 @@ def num2words(number, ordinal=False, lang='en', to='cardinal', **kwargs): # backwards compatible if ordinal: - to = 'ordinal' + to = "ordinal" if to not in CONVERTES_TYPES: raise NotImplementedError() - return getattr(converter, 'to_{}'.format(to))(number, **kwargs) + return getattr(converter, "to_{}".format(to))(number, **kwargs) diff --git a/num2words/lang_CZ.py b/num2words/lang_CS.py similarity index 54% rename from num2words/lang_CZ.py rename to num2words/lang_CS.py index 04c44a07..246e547a 100644 --- a/num2words/lang_CZ.py +++ b/num2words/lang_CS.py @@ -20,78 +20,74 @@ from .base import Num2Word_Base from .utils import get_digits, splitbyx -ZERO = ('nula',) +ZERO = ("nula",) ONES = { - 1: ('jedna',), - 2: ('dva',), - 3: ('tři',), - 4: ('čtyři',), - 5: ('pět',), - 6: ('šest',), - 7: ('sedm',), - 8: ('osm',), - 9: ('devět',), + 1: ("jedna",), + 2: ("dva",), + 3: ("tři",), + 4: ("čtyři",), + 5: ("pět",), + 6: ("šest",), + 7: ("sedm",), + 8: ("osm",), + 9: ("devět",), } TENS = { - 0: ('deset',), - 1: ('jedenáct',), - 2: ('dvanáct',), - 3: ('třináct',), - 4: ('čtrnáct',), - 5: ('patnáct',), - 6: ('šestnáct',), - 7: ('sedmnáct',), - 8: ('osmnáct',), - 9: ('devatenáct',), + 0: ("deset",), + 1: ("jedenáct",), + 2: ("dvanáct",), + 3: ("třináct",), + 4: ("čtrnáct",), + 5: ("patnáct",), + 6: ("šestnáct",), + 7: ("sedmnáct",), + 8: ("osmnáct",), + 9: ("devatenáct",), } TWENTIES = { - 2: ('dvacet',), - 3: ('třicet',), - 4: ('čtyřicet',), - 5: ('padesát',), - 6: ('šedesát',), - 7: ('sedmdesát',), - 8: ('osmdesát',), - 9: ('devadesát',), + 2: ("dvacet",), + 3: ("třicet",), + 4: ("čtyřicet",), + 5: ("padesát",), + 6: ("šedesát",), + 7: ("sedmdesát",), + 8: ("osmdesát",), + 9: ("devadesát",), } HUNDREDS = { - 1: ('sto',), - 2: ('dvěstě',), - 3: ('třista',), - 4: ('čtyřista',), - 5: ('pětset',), - 6: ('šestset',), - 7: ('sedmset',), - 8: ('osmset',), - 9: ('devětset',), + 1: ("sto",), + 2: ("dvěstě",), + 3: ("třista",), + 4: ("čtyřista",), + 5: ("pětset",), + 6: ("šestset",), + 7: ("sedmset",), + 8: ("osmset",), + 9: ("devětset",), } THOUSANDS = { - 1: ('tisíc', 'tisíce', 'tisíc'), # 10^3 - 2: ('milion', 'miliony', 'milionů'), # 10^6 - 3: ('miliarda', 'miliardy', 'miliard'), # 10^9 - 4: ('bilion', 'biliony', 'bilionů'), # 10^12 - 5: ('biliarda', 'biliardy', 'biliard'), # 10^15 - 6: ('trilion', 'triliony', 'trilionů'), # 10^18 - 7: ('triliarda', 'triliardy', 'triliard'), # 10^21 - 8: ('kvadrilion', 'kvadriliony', 'kvadrilionů'), # 10^24 - 9: ('kvadriliarda', 'kvadriliardy', 'kvadriliard'), # 10^27 - 10: ('quintillion', 'quintilliony', 'quintillionů'), # 10^30 + 1: ("tisíc", "tisíce", "tisíc"), # 10^3 + 2: ("milion", "miliony", "milionů"), # 10^6 + 3: ("miliarda", "miliardy", "miliard"), # 10^9 + 4: ("bilion", "biliony", "bilionů"), # 10^12 + 5: ("biliarda", "biliardy", "biliard"), # 10^15 + 6: ("trilion", "triliony", "trilionů"), # 10^18 + 7: ("triliarda", "triliardy", "triliard"), # 10^21 + 8: ("kvadrilion", "kvadriliony", "kvadrilionů"), # 10^24 + 9: ("kvadriliarda", "kvadriliardy", "kvadriliard"), # 10^27 + 10: ("quintillion", "quintilliony", "quintillionů"), # 10^30 } -class Num2Word_CZ(Num2Word_Base): +class Num2Word_CS(Num2Word_Base): CURRENCY_FORMS = { - 'CZK': ( - ('koruna', 'koruny', 'korun'), ('halíř', 'halíře', 'haléřů') - ), - 'EUR': ( - ('euro', 'euro', 'euro'), ('cent', 'centy', 'centů') - ), + "CZK": (("koruna", "koruny", "korun"), ("halíř", "halíře", "haléřů")), + "EUR": (("euro", "euro", "euro"), ("cent", "centy", "centů")), } def setup(self): @@ -99,16 +95,16 @@ def setup(self): self.pointword = "celá" 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' % ( + n = str(number).replace(",", ".") + if "." in n: + left, right = n.split(".") + leading_zero_count = len(right) - len(right.lstrip("0")) + leading_zeros = (ZERO[0] + " ") * leading_zero_count + decimal_part = leading_zeros + self._int2word(int(right)) + return "%s %s %s" % ( self._int2word(int(left)), self.pointword, - decimal_part + decimal_part, ) else: return self._int2word(int(n)) @@ -154,4 +150,4 @@ def _int2word(self, n): if i > 0: words.append(self.pluralize(x, THOUSANDS[i])) - return ' '.join(words) + return " ".join(words) diff --git a/num2words/lang_DK.py b/num2words/lang_DA.py similarity index 60% rename from num2words/lang_DK.py rename to num2words/lang_DA.py index 50ab110c..b3da892b 100644 --- a/num2words/lang_DK.py +++ b/num2words/lang_DA.py @@ -20,62 +20,89 @@ from . import lang_EU -class Num2Word_DK(lang_EU.Num2Word_EU): +class Num2Word_DA(lang_EU.Num2Word_EU): GIGA_SUFFIX = "illiarder" MEGA_SUFFIX = "illioner" def setup(self): - super(Num2Word_DK, self).setup() + super(Num2Word_DA, self).setup() self.negword = "minus " self.pointword = "komma" self.exclude_title = ["og", "komma", "minus"] - self.mid_numwords = [(1000, "tusind"), (100, "hundrede"), - (90, "halvfems"), (80, "firs"), - (70, "halvfjerds"), (60, "treds"), - (50, "halvtreds"), (40, "fyrre"), (30, "tredive")] - self.low_numwords = ["tyve", "nitten", "atten", "sytten", - "seksten", "femten", "fjorten", "tretten", - "tolv", "elleve", "ti", "ni", "otte", - "syv", "seks", "fem", "fire", "tre", "to", - "et", "nul"] - self.ords = {"nul": "nul", - "et": "f\xf8rste", - "to": "anden", - "tre": "tredje", - "fire": "fjerde", - "fem": "femte", - "seks": "sjette", - "syv": "syvende", - "otte": "ottende", - "ni": "niende", - "ti": "tiende", - "elleve": "ellevte", - "tolv": "tolvte", - "tretten": "trett", - "fjorten": "fjort", - "femten": "femt", - "seksten": "sekst", - "sytten": "sytt", - "atten": "att", - "nitten": "nitt", - "tyve": "tyv"} + self.mid_numwords = [ + (1000, "tusind"), + (100, "hundrede"), + (90, "halvfems"), + (80, "firs"), + (70, "halvfjerds"), + (60, "treds"), + (50, "halvtreds"), + (40, "fyrre"), + (30, "tredive"), + ] + self.low_numwords = [ + "tyve", + "nitten", + "atten", + "sytten", + "seksten", + "femten", + "fjorten", + "tretten", + "tolv", + "elleve", + "ti", + "ni", + "otte", + "syv", + "seks", + "fem", + "fire", + "tre", + "to", + "et", + "nul", + ] + self.ords = { + "nul": "nul", + "et": "f\xf8rste", + "to": "anden", + "tre": "tredje", + "fire": "fjerde", + "fem": "femte", + "seks": "sjette", + "syv": "syvende", + "otte": "ottende", + "ni": "niende", + "ti": "tiende", + "elleve": "ellevte", + "tolv": "tolvte", + "tretten": "trett", + "fjorten": "fjort", + "femten": "femt", + "seksten": "sekst", + "sytten": "sytt", + "atten": "att", + "nitten": "nitt", + "tyve": "tyv", + } self.ordflag = False def merge(self, curr, next): ctext, cnum, ntext, nnum = curr + next if next[1] == 100 or next[1] == 1000: lst = list(next) - lst[0] = 'et' + lst[0] + lst[0] = "et" + lst[0] next = tuple(lst) if cnum == 1: - if nnum < 10 ** 6 or self.ordflag: + if nnum < 10**6 or self.ordflag: return next ctext = "en" if nnum > cnum: - if nnum >= 10 ** 6: + if nnum >= 10**6: ctext += " " val = cnum * nnum else: @@ -87,7 +114,7 @@ def merge(self, curr, next): if nnum == 1: ntext = "en" ntext, ctext = ctext, ntext + "og" - elif cnum >= 10 ** 6: + elif cnum >= 10**6: ctext += " " val = cnum + nnum word = ctext + ntext @@ -100,7 +127,7 @@ def to_ordinal(self, value): self.ordflag = False for key in self.ords: if outword.endswith(key): - outword = outword[:len(outword) - len(key)] + self.ords[key] + outword = outword[: len(outword) - len(key)] + self.ords[key] break if value % 100 >= 30 and value % 100 <= 39 or value % 100 == 0: outword += "te" @@ -119,15 +146,20 @@ def to_ordinal_num(self, value): def to_currency(self, val, longval=True): if val // 100 == 1 or val == 1: - ret = self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re", - jointxt="og", longval=longval) + ret = self.to_splitnum( + val, hightxt="kr", + lowtxt="\xf8re", + jointxt="og", + longval=longval + ) return "en " + ret[3:] - return self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re", - jointxt="og", longval=longval) + return self.to_splitnum( + val, hightxt="kr", lowtxt="\xf8re", jointxt="og", longval=longval + ) def to_year(self, val, longval=True): if val == 1: - return 'en' + return "en" if not (val // 100) % 10: return self.to_cardinal(val) return self.to_splitnum(val, hightxt="hundrede", longval=longval) diff --git a/num2words/lang_KZ.py b/num2words/lang_KK.py similarity index 64% rename from num2words/lang_KZ.py rename to num2words/lang_KK.py index 67df20ed..35b46d57 100644 --- a/num2words/lang_KZ.py +++ b/num2words/lang_KK.py @@ -20,53 +20,53 @@ from .base import Num2Word_Base from .utils import get_digits, splitbyx -ZERO = 'нөл' +ZERO = "нөл" ONES = { - 1: 'бір', - 2: 'екі', - 3: 'үш', - 4: 'төрт', - 5: 'бес', - 6: 'алты', - 7: 'жеті', - 8: 'сегіз', - 9: 'тоғыз', + 1: "бір", + 2: "екі", + 3: "үш", + 4: "төрт", + 5: "бес", + 6: "алты", + 7: "жеті", + 8: "сегіз", + 9: "тоғыз", } -TEN = 'он' +TEN = "он" TWENTIES = { - 2: 'жиырма', - 3: 'отыз', - 4: 'қырық', - 5: 'елу', - 6: 'алпыс', - 7: 'жетпіс', - 8: 'сексен', - 9: 'тоқсан', + 2: "жиырма", + 3: "отыз", + 4: "қырық", + 5: "елу", + 6: "алпыс", + 7: "жетпіс", + 8: "сексен", + 9: "тоқсан", } -HUNDRED = 'жүз' +HUNDRED = "жүз" THOUSANDS = { - 1: 'мың', - 2: 'миллион', - 3: 'миллиард', - 4: 'триллион', - 5: 'квадриллион', - 6: 'квинтиллион', - 7: 'секстиллион', - 8: 'септиллион', - 9: 'октиллион', - 10: 'нониллион', + 1: "мың", + 2: "миллион", + 3: "миллиард", + 4: "триллион", + 5: "квадриллион", + 6: "квинтиллион", + 7: "секстиллион", + 8: "септиллион", + 9: "октиллион", + 10: "нониллион", } -class Num2Word_KZ(Num2Word_Base): +class Num2Word_KK(Num2Word_Base): CURRENCY_FORMS = { - 'USD': ('доллар', 'цент'), - 'KZT': ('теңге', 'тиын'), + "USD": ("доллар", "цент"), + "KZT": ("теңге", "тиын"), } def setup(self): @@ -74,14 +74,14 @@ def setup(self): self.pointword = "бүтін" 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' % ( + n = str(number).replace(",", ".") + if "." in n: + left, right = n.split(".") + leading_zero_count = len(right) - len(right.lstrip("0")) + return "%s %s %s" % ( self._int2word(int(left)), self.pointword, - (ZERO + ' ') * leading_zero_count + self._int2word(int(right)) + (ZERO + " ") * leading_zero_count + self._int2word(int(right)), ) else: return self._int2word(int(n)) @@ -90,11 +90,11 @@ def pluralize(self, n, form): return form def _cents_verbose(self, number, currency): - return self._int2word(number, currency == 'KZT') + return self._int2word(number, currency == "KZT") def _int2word(self, n, feminine=False): if n < 0: - return ' '.join([self.negword, self._int2word(abs(n))]) + return " ".join([self.negword, self._int2word(abs(n))]) if n == 0: return ZERO @@ -126,7 +126,7 @@ def _int2word(self, n, feminine=False): if i > 0: words.append(THOUSANDS[i]) - return ' '.join(words) + return " ".join(words) def to_ordinal(self, number): # TODO: Implement to_ordinal diff --git a/tests/test_cz.py b/tests/test_cs.py similarity index 51% rename from tests/test_cz.py rename to tests/test_cs.py index 1801e8f7..bde0bf29 100644 --- a/tests/test_cz.py +++ b/tests/test_cs.py @@ -24,91 +24,98 @@ class Num2WordsCZTest(TestCase): def test_cardinal(self): - self.assertEqual(num2words(100, lang='cz'), "sto") - self.assertEqual(num2words(101, lang='cz'), "sto jedna") - self.assertEqual(num2words(110, lang='cz'), "sto deset") - self.assertEqual(num2words(115, lang='cz'), "sto patnáct") - self.assertEqual(num2words(123, lang='cz'), "sto dvacet tři") - self.assertEqual(num2words(1000, lang='cz'), "tisíc") - self.assertEqual(num2words(1001, lang='cz'), "tisíc jedna") - self.assertEqual(num2words(2012, lang='cz'), "dva tisíce dvanáct") - self.assertEqual( - num2words(10.02, lang='cz'), - "deset celá nula dva" - ) - self.assertEqual( - num2words(15.007, lang='cz'), - "patnáct celá nula nula sedm" - ) - self.assertEqual( - num2words(12519.85, lang='cz'), + self.assertEqual(num2words(100, lang="cs"), "sto") + self.assertEqual(num2words(101, lang="cs"), "sto jedna") + self.assertEqual(num2words(110, lang="cs"), "sto deset") + self.assertEqual(num2words(115, lang="cs"), "sto patnáct") + self.assertEqual(num2words(123, lang="cs"), "sto dvacet tři") + self.assertEqual(num2words(1000, lang="cs"), "tisíc") + self.assertEqual(num2words(1001, lang="cs"), "tisíc jedna") + self.assertEqual(num2words(2012, lang="cs"), "dva tisíce dvanáct") + self.assertEqual(num2words(10.02, lang="cs"), "deset celá nula dva") + self.assertEqual(num2words(15.007, lang="cs"), + "patnáct celá nula nula sedm") + self.assertEqual( + num2words(12519.85, lang="cs"), "dvanáct tisíc pětset devatenáct celá osmdesát pět" ) + self.assertEqual(num2words(123.50, lang="cs"), + "sto dvacet tři celá pět") self.assertEqual( - num2words(123.50, lang='cz'), - "sto dvacet tři celá pět" - ) - self.assertEqual( - num2words(1234567890, lang='cz'), + num2words(1234567890, lang="cs"), "miliarda dvěstě třicet čtyři miliony pětset šedesát " - "sedm tisíc osmset devadesát" + "sedm tisíc osmset devadesát", ) self.assertEqual( - num2words(215461407892039002157189883901676, lang='cz'), + num2words(215461407892039002157189883901676, lang="cs"), "dvěstě patnáct quintillionů čtyřista šedesát jedna kvadriliard " "čtyřista sedm kvadrilionů osmset devadesát dva triliardy třicet " "devět trilionů dva biliardy sto padesát sedm bilionů sto " "osmdesát devět miliard osmset osmdesát tři miliony " - "devětset jedna tisíc šestset sedmdesát šest" + "devětset jedna tisíc šestset sedmdesát šest", ) self.assertEqual( - num2words(719094234693663034822824384220291, lang='cz'), + num2words(719094234693663034822824384220291, lang="cs"), "sedmset devatenáct quintillionů devadesát " "čtyři kvadriliardy dvěstě třicet čtyři " "kvadriliony šestset devadesát tři triliardy " "šestset šedesát tři triliony třicet čtyři biliardy osmset " "dvacet dva biliony osmset dvacet čtyři " "miliardy třista osmdesát čtyři miliony dvěstě dvacet " - "tisíc dvěstě devadesát jedna" + "tisíc dvěstě devadesát jedna", ) def test_to_ordinal(self): # @TODO: implement to_ordinal with self.assertRaises(NotImplementedError): - num2words(1, lang='cz', to='ordinal') + num2words(1, lang="cs", to="ordinal") def test_currency(self): self.assertEqual( - num2words(10.0, lang='cz', to='currency', currency='EUR'), - "deset euro, nula centů") + num2words(10.0, lang="cs", to="currency", currency="EUR"), + "deset euro, nula centů", + ) self.assertEqual( - num2words(1.0, lang='cz', to='currency', currency='CZK'), - "jedna koruna, nula haléřů") + num2words(1.0, lang="cs", to="currency", currency="CZK"), + "jedna koruna, nula haléřů", + ) self.assertEqual( - num2words(1234.56, lang='cz', to='currency', currency='EUR'), - "tisíc dvěstě třicet čtyři euro, padesát šest centů") + num2words(1234.56, lang="cs", to="currency", currency="EUR"), + "tisíc dvěstě třicet čtyři euro, padesát šest centů", + ) self.assertEqual( - num2words(1234.56, lang='cz', to='currency', currency='CZK'), - "tisíc dvěstě třicet čtyři koruny, padesát šest haléřů") + num2words(1234.56, lang="cs", to="currency", currency="CZK"), + "tisíc dvěstě třicet čtyři koruny, padesát šest haléřů", + ) self.assertEqual( - num2words(101.11, lang='cz', to='currency', currency='EUR', - separator=' a'), - "sto jedna euro a jedenáct centů") + num2words(101.11, + lang="cs", + to="currency", + currency="EUR", + separator=" a"), + "sto jedna euro a jedenáct centů", + ) self.assertEqual( - num2words(101.21, lang='cz', to='currency', currency='CZK', - separator=' a'), - "sto jedna korun a dvacet jedna haléřů" + num2words(101.21, + lang="cs", + to="currency", + currency="CZK", + separator=" a"), + "sto jedna korun a dvacet jedna haléřů", ) self.assertEqual( - num2words(-12519.85, lang='cz', to='currency', cents=False), - "mínus dvanáct tisíc pětset devatenáct euro, 85 centů" + num2words(-12519.85, lang="cs", to="currency", cents=False), + "mínus dvanáct tisíc pětset devatenáct euro, 85 centů", ) self.assertEqual( - num2words(123.50, lang='cz', to='currency', currency='CZK', - separator=' a'), - "sto dvacet tři koruny a padesát haléřů" + num2words(123.50, + lang="cs", + to="currency", + currency="CZK", + separator=" a"), + "sto dvacet tři koruny a padesát haléřů", ) self.assertEqual( - num2words(19.50, lang='cz', to='currency', cents=False), - "devatenáct euro, 50 centů" + num2words(19.50, lang="cs", to="currency", cents=False), + "devatenáct euro, 50 centů", ) diff --git a/tests/test_dk.py b/tests/test_da.py similarity index 64% rename from tests/test_dk.py rename to tests/test_da.py index 889e9d8e..46b0928c 100644 --- a/tests/test_dk.py +++ b/tests/test_da.py @@ -22,16 +22,16 @@ from num2words import num2words -class Num2WordsDKTest(TestCase): +class Num2WordsDATest(TestCase): def test_ordinal(self): - self.assertEqual(num2words(1, to="ordinal", lang="dk"), "første") - self.assertEqual(num2words(5, to="ordinal", lang="dk"), "femte") + self.assertEqual(num2words(1, to="ordinal", lang="da"), "første") + self.assertEqual(num2words(5, to="ordinal", lang="da"), "femte") def test_cardinal(self): - self.assertEqual(num2words(0, to="cardinal", lang="dk"), "nul") - self.assertEqual(num2words(1, to="cardinal", lang="dk"), "et") - self.assertEqual(num2words(2, to="cardinal", lang="dk"), "to") - self.assertEqual(num2words(5, to="cardinal", lang="dk"), "fem") - self.assertEqual(num2words(8, to="cardinal", lang="dk"), "otte") - self.assertEqual(num2words(18, to="cardinal", lang="dk"), "atten") - self.assertEqual(num2words(45, to="cardinal", lang="dk"), "femogfyrre") + self.assertEqual(num2words(0, to="cardinal", lang="da"), "nul") + self.assertEqual(num2words(1, to="cardinal", lang="da"), "et") + self.assertEqual(num2words(2, to="cardinal", lang="da"), "to") + self.assertEqual(num2words(5, to="cardinal", lang="da"), "fem") + self.assertEqual(num2words(8, to="cardinal", lang="da"), "otte") + self.assertEqual(num2words(18, to="cardinal", lang="da"), "atten") + self.assertEqual(num2words(45, to="cardinal", lang="da"), "femogfyrre") diff --git a/tests/test_kz.py b/tests/test_kk.py similarity index 64% rename from tests/test_kz.py rename to tests/test_kk.py index 83435640..2ad37b09 100644 --- a/tests/test_kz.py +++ b/tests/test_kk.py @@ -22,60 +22,53 @@ from num2words import num2words -class Num2WordsKZTest(TestCase): +class Num2WordsKKTest(TestCase): def test_to_cardinal(self): self.maxDiff = None - self.assertEqual(num2words(7, lang="kz"), "жеті") - self.assertEqual(num2words(23, lang="kz"), "жиырма үш") - self.assertEqual(num2words(145, lang="kz"), "жүз қырық бес") + self.assertEqual(num2words(7, lang="kk"), "жеті") + self.assertEqual(num2words(23, lang="kk"), "жиырма үш") + self.assertEqual(num2words(145, lang="kk"), "жүз қырық бес") + self.assertEqual(num2words(2869, lang="kk"), + "екі мың сегіз жүз алпыс тоғыз") self.assertEqual( - num2words(2869, lang="kz"), - "екі мың сегіз жүз алпыс тоғыз" - ) - self.assertEqual( - num2words(-789000125, lang="kz"), + num2words(-789000125, lang="kk"), "минус жеті жүз сексен тоғыз миллион жүз жиырма бес", ) self.assertEqual( - num2words(84932, lang="kz"), "сексен төрт мың тоғыз жүз отыз екі" + num2words(84932, lang="kk"), "сексен төрт мың тоғыз жүз отыз екі" ) def test_to_cardinal_floats(self): - self.assertEqual(num2words(100.67, lang="kz"), "жүз бүтін алпыс жеті") - self.assertEqual(num2words(0.7, lang="kz"), "нөл бүтін жеті") - self.assertEqual(num2words(1.73, lang="kz"), "бір бүтін жетпіс үш") - self.assertEqual( - num2words(10.02, lang='kz'), - "он бүтін нөл екі" - ) - self.assertEqual( - num2words(15.007, lang='kz'), - "он бес бүтін нөл нөл жеті" - ) + self.assertEqual(num2words(100.67, lang="kk"), "жүз бүтін алпыс жеті") + self.assertEqual(num2words(0.7, lang="kk"), "нөл бүтін жеті") + self.assertEqual(num2words(1.73, lang="kk"), "бір бүтін жетпіс үш") + self.assertEqual(num2words(10.02, lang="kk"), "он бүтін нөл екі") + self.assertEqual(num2words(15.007, lang="kk"), + "он бес бүтін нөл нөл жеті") def test_to_ordinal(self): with self.assertRaises(NotImplementedError): - num2words(1, lang="kz", to="ordinal") + num2words(1, lang="kk", to="ordinal") def test_to_currency(self): self.assertEqual( - num2words(25.24, lang="kz", to="currency", currency="KZT"), + num2words(25.24, lang="kk", to="currency", currency="KZT"), "жиырма бес теңге, жиырма төрт тиын", ) self.assertEqual( - num2words(1996.4, lang="kz", to="currency", currency="KZT"), + num2words(1996.4, lang="kk", to="currency", currency="KZT"), "бір мың тоғыз жүз тоқсан алты теңге, қырық тиын", ) self.assertEqual( - num2words(632924.51, lang="kz", to="currency", currency="KZT"), + num2words(632924.51, lang="kk", to="currency", currency="KZT"), "алты жүз отыз екі мың тоғыз жүз жиырма төрт теңге, елу бір тиын", ) self.assertEqual( - num2words(632924.513, lang="kz", to="currency", currency="KZT"), + num2words(632924.513, lang="kk", to="currency", currency="KZT"), "алты жүз отыз екі мың тоғыз жүз жиырма төрт теңге, елу бір тиын", ) self.assertEqual( - num2words(987654321.123, lang="kz", to="currency", currency="KZT"), + num2words(987654321.123, lang="kk", to="currency", currency="KZT"), "тоғыз жүз сексен жеті миллион алты жүз елу төрт мың " "үш жүз жиырма бір теңге, он екі тиын", )