mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Initial kazakh implementation
This commit is contained in:
committed by
Ernesto Rodriguez Ortiz
parent
e06493ceda
commit
d576817c7f
@@ -20,9 +20,9 @@ from __future__ import unicode_literals
|
|||||||
from . import (lang_AR, lang_CZ, lang_DE, lang_DK, lang_EN, lang_EN_IN,
|
from . import (lang_AR, lang_CZ, lang_DE, lang_DK, lang_EN, lang_EN_IN,
|
||||||
lang_ES, lang_ES_CO, lang_ES_NI, lang_ES_VE, lang_FI, lang_FR,
|
lang_ES, lang_ES_CO, lang_ES_NI, lang_ES_VE, lang_FI, lang_FR,
|
||||||
lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE, lang_ID, lang_IT,
|
lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE, lang_ID, lang_IT,
|
||||||
lang_JA, lang_KN, lang_KO, lang_LT, lang_LV, lang_NL, lang_NO,
|
lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT, lang_LV, lang_NL,
|
||||||
lang_PL, lang_PT, lang_PT_BR, lang_RO, lang_RU, lang_SL,
|
lang_NO, lang_PL, lang_PT, lang_PT_BR, lang_RO, lang_RU,
|
||||||
lang_SR, lang_TE, lang_TH, lang_TR, lang_UK, lang_VI)
|
lang_SL, lang_SR, lang_TE, lang_TH, lang_TR, lang_UK, lang_VI)
|
||||||
|
|
||||||
CONVERTER_CLASSES = {
|
CONVERTER_CLASSES = {
|
||||||
'ar': lang_AR.Num2Word_AR(),
|
'ar': lang_AR.Num2Word_AR(),
|
||||||
@@ -43,6 +43,7 @@ CONVERTER_CLASSES = {
|
|||||||
'ja': lang_JA.Num2Word_JA(),
|
'ja': lang_JA.Num2Word_JA(),
|
||||||
'kn': lang_KN.Num2Word_KN(),
|
'kn': lang_KN.Num2Word_KN(),
|
||||||
'ko': lang_KO.Num2Word_KO(),
|
'ko': lang_KO.Num2Word_KO(),
|
||||||
|
'kz': lang_KZ.Num2Word_KZ(),
|
||||||
'lt': lang_LT.Num2Word_LT(),
|
'lt': lang_LT.Num2Word_LT(),
|
||||||
'lv': lang_LV.Num2Word_LV(),
|
'lv': lang_LV.Num2Word_LV(),
|
||||||
'pl': lang_PL.Num2Word_PL(),
|
'pl': lang_PL.Num2Word_PL(),
|
||||||
|
|||||||
134
num2words/lang_KZ.py
Normal file
134
num2words/lang_KZ.py
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# 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 __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .base import Num2Word_Base
|
||||||
|
from .utils import get_digits, splitbyx
|
||||||
|
|
||||||
|
|
||||||
|
ZERO = 'нөл'
|
||||||
|
|
||||||
|
ONES = {
|
||||||
|
1: 'бір',
|
||||||
|
2: 'екі',
|
||||||
|
3: 'үш',
|
||||||
|
4: 'төрт',
|
||||||
|
5: 'бес',
|
||||||
|
6: 'алты',
|
||||||
|
7: 'жеті',
|
||||||
|
8: 'сегіз',
|
||||||
|
9: 'тоғыз',
|
||||||
|
}
|
||||||
|
|
||||||
|
TEN = 'он'
|
||||||
|
|
||||||
|
TWENTIES = {
|
||||||
|
2: 'жиырма',
|
||||||
|
3: 'отыз',
|
||||||
|
4: 'қырық',
|
||||||
|
5: 'елу',
|
||||||
|
6: 'алпыс',
|
||||||
|
7: 'жетпіс',
|
||||||
|
8: 'сексен',
|
||||||
|
9: 'тоқсан',
|
||||||
|
}
|
||||||
|
|
||||||
|
HUNDRED = 'жүз'
|
||||||
|
|
||||||
|
THOUSANDS = {
|
||||||
|
1: 'мың',
|
||||||
|
2: 'миллион',
|
||||||
|
3: 'миллиард',
|
||||||
|
4: 'триллион',
|
||||||
|
5: 'квадриллион',
|
||||||
|
6: 'квинтиллион',
|
||||||
|
7: 'секстиллион',
|
||||||
|
8: 'септиллион',
|
||||||
|
9: 'октиллион',
|
||||||
|
10: 'нониллион',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Num2Word_KZ(Num2Word_Base):
|
||||||
|
CURRENCY_FORMS = {
|
||||||
|
'USD': ('доллар', 'цент'),
|
||||||
|
'KZT': ('теңге', 'тиын'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.negword = "минус"
|
||||||
|
self.pointword = "бүтін"
|
||||||
|
|
||||||
|
def to_cardinal(self, number):
|
||||||
|
n = str(number).replace(',', '.')
|
||||||
|
if '.' in n:
|
||||||
|
left, right = n.split('.')
|
||||||
|
return u'%s %s %s' % (
|
||||||
|
self._int2word(int(left)),
|
||||||
|
self.pointword,
|
||||||
|
self._int2word(int(right))
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return self._int2word(int(n))
|
||||||
|
|
||||||
|
def pluralize(self, n, form):
|
||||||
|
return form
|
||||||
|
|
||||||
|
def _cents_verbose(self, number, currency):
|
||||||
|
return self._int2word(number, currency == 'KZT')
|
||||||
|
|
||||||
|
def _int2word(self, n, feminine=False):
|
||||||
|
if n < 0:
|
||||||
|
return ' '.join([self.negword, self._int2word(abs(n))])
|
||||||
|
|
||||||
|
if n == 0:
|
||||||
|
return ZERO
|
||||||
|
|
||||||
|
words = []
|
||||||
|
chunks = list(splitbyx(str(n), 3))
|
||||||
|
i = len(chunks)
|
||||||
|
for x in chunks:
|
||||||
|
i -= 1
|
||||||
|
|
||||||
|
if x == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
n1, n2, n3 = get_digits(x)
|
||||||
|
|
||||||
|
if n3 > 0:
|
||||||
|
if n3 > 1:
|
||||||
|
words.append(ONES[n3])
|
||||||
|
words.append(HUNDRED)
|
||||||
|
|
||||||
|
if n2 == 1:
|
||||||
|
words.append(TEN)
|
||||||
|
elif n2 > 1:
|
||||||
|
words.append(TWENTIES[n2])
|
||||||
|
|
||||||
|
if n1 > 0:
|
||||||
|
words.append(ONES[n1])
|
||||||
|
|
||||||
|
if i > 0:
|
||||||
|
words.append(THOUSANDS[i])
|
||||||
|
|
||||||
|
return ' '.join(words)
|
||||||
|
|
||||||
|
def to_ordinal(self, number):
|
||||||
|
# TODO: Implement to_ordinal
|
||||||
|
raise NotImplementedError()
|
||||||
45
tests/test_kz.py
Normal file
45
tests/test_kz.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# 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 __future__ import unicode_literals
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from num2words import num2words
|
||||||
|
|
||||||
|
|
||||||
|
class Num2WordsKZTest(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(2869, lang='kz'), 'екі мың сегіз жүз алпыс тоғыз')
|
||||||
|
self.assertEqual(num2words(84932, lang='kz'), 'сексен төрт мың тоғыз жүз отыз екі')
|
||||||
|
|
||||||
|
def test_to_cardinal_floats(self):
|
||||||
|
self.assertEqual(num2words(100.67, lang='kz'), 'жүз бүтін алпыс жеті')
|
||||||
|
|
||||||
|
def test_to_ordinal(self):
|
||||||
|
with self.assertRaises(NotImplementedError):
|
||||||
|
num2words(1, lang='kz', to='ordinal')
|
||||||
|
|
||||||
|
def test_to_currency(self):
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(25.24, lang='kz', to='currency', currency='KZT'),
|
||||||
|
'жиырма бес теңге, жиырма төрт тиын'
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user