num2words2 0.1.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- num2words2/README.md +69 -0
- num2words2/__init__.py +196 -0
- num2words2/_version.py +3 -0
- num2words2/base.py +377 -0
- num2words2/compat.py +29 -0
- num2words2/currency.py +60 -0
- num2words2/lang_AF.py +202 -0
- num2words2/lang_AM.py +193 -0
- num2words2/lang_AR.py +435 -0
- num2words2/lang_AS.py +119 -0
- num2words2/lang_AZ.py +208 -0
- num2words2/lang_BA.py +119 -0
- num2words2/lang_BE.py +356 -0
- num2words2/lang_BG.py +393 -0
- num2words2/lang_BN.py +242 -0
- num2words2/lang_BO.py +122 -0
- num2words2/lang_BR.py +135 -0
- num2words2/lang_BS.py +189 -0
- num2words2/lang_CA.py +476 -0
- num2words2/lang_CE.py +546 -0
- num2words2/lang_CS.py +260 -0
- num2words2/lang_CY.py +574 -0
- num2words2/lang_DA.py +170 -0
- num2words2/lang_DE.py +180 -0
- num2words2/lang_EL.py +338 -0
- num2words2/lang_EN.py +118 -0
- num2words2/lang_EN_IN.py +26 -0
- num2words2/lang_EN_NG.py +45 -0
- num2words2/lang_EO.py +130 -0
- num2words2/lang_ES.py +399 -0
- num2words2/lang_ES_CO.py +37 -0
- num2words2/lang_ES_CR.py +38 -0
- num2words2/lang_ES_GT.py +37 -0
- num2words2/lang_ES_NI.py +35 -0
- num2words2/lang_ES_VE.py +43 -0
- num2words2/lang_ET.py +393 -0
- num2words2/lang_EU.py +158 -0
- num2words2/lang_EUR.py +104 -0
- num2words2/lang_FA.py +187 -0
- num2words2/lang_FI.py +759 -0
- num2words2/lang_FO.py +136 -0
- num2words2/lang_FR.py +133 -0
- num2words2/lang_FR_BE.py +49 -0
- num2words2/lang_FR_CH.py +48 -0
- num2words2/lang_FR_DZ.py +35 -0
- num2words2/lang_GL.py +135 -0
- num2words2/lang_GU.py +172 -0
- num2words2/lang_HA.py +293 -0
- num2words2/lang_HAW.py +144 -0
- num2words2/lang_HE.py +314 -0
- num2words2/lang_HI.py +243 -0
- num2words2/lang_HR.py +304 -0
- num2words2/lang_HT.py +136 -0
- num2words2/lang_HU.py +189 -0
- num2words2/lang_HY.py +364 -0
- num2words2/lang_ID.py +242 -0
- num2words2/lang_IS.py +208 -0
- num2words2/lang_IT.py +265 -0
- num2words2/lang_JA.py +615 -0
- num2words2/lang_JW.py +136 -0
- num2words2/lang_KA.py +169 -0
- num2words2/lang_KK.py +136 -0
- num2words2/lang_KM.py +173 -0
- num2words2/lang_KN.py +182 -0
- num2words2/lang_KO.py +175 -0
- num2words2/lang_KZ.py +161 -0
- num2words2/lang_LA.py +135 -0
- num2words2/lang_LB.py +135 -0
- num2words2/lang_LN.py +136 -0
- num2words2/lang_LO.py +149 -0
- num2words2/lang_LT.py +283 -0
- num2words2/lang_LV.py +266 -0
- num2words2/lang_MG.py +143 -0
- num2words2/lang_MI.py +151 -0
- num2words2/lang_MK.py +136 -0
- num2words2/lang_ML.py +159 -0
- num2words2/lang_MN.py +319 -0
- num2words2/lang_MR.py +187 -0
- num2words2/lang_MS.py +293 -0
- num2words2/lang_MT.py +159 -0
- num2words2/lang_MY.py +152 -0
- num2words2/lang_NE.py +157 -0
- num2words2/lang_NL.py +204 -0
- num2words2/lang_NN.py +136 -0
- num2words2/lang_NO.py +143 -0
- num2words2/lang_OC.py +135 -0
- num2words2/lang_PA.py +159 -0
- num2words2/lang_PL.py +336 -0
- num2words2/lang_PS.py +136 -0
- num2words2/lang_PT.py +280 -0
- num2words2/lang_PT_BR.py +224 -0
- num2words2/lang_RO.py +183 -0
- num2words2/lang_RU.py +570 -0
- num2words2/lang_SA.py +136 -0
- num2words2/lang_SD.py +136 -0
- num2words2/lang_SI.py +152 -0
- num2words2/lang_SK.py +250 -0
- num2words2/lang_SL.py +306 -0
- num2words2/lang_SN.py +447 -0
- num2words2/lang_SO.py +136 -0
- num2words2/lang_SQ.py +252 -0
- num2words2/lang_SR.py +254 -0
- num2words2/lang_SU.py +136 -0
- num2words2/lang_SV.py +169 -0
- num2words2/lang_SW.py +219 -0
- num2words2/lang_TA.py +303 -0
- num2words2/lang_TE.py +169 -0
- num2words2/lang_TET.py +285 -0
- num2words2/lang_TG.py +149 -0
- num2words2/lang_TH.py +214 -0
- num2words2/lang_TK.py +136 -0
- num2words2/lang_TL.py +145 -0
- num2words2/lang_TR.py +882 -0
- num2words2/lang_TT.py +136 -0
- num2words2/lang_UK.py +1101 -0
- num2words2/lang_UR.py +168 -0
- num2words2/lang_UZ.py +136 -0
- num2words2/lang_VI.py +143 -0
- num2words2/lang_WO.py +136 -0
- num2words2/lang_YI.py +135 -0
- num2words2/lang_YO.py +136 -0
- num2words2/lang_ZH.py +296 -0
- num2words2/lang_ZH_CN.py +85 -0
- num2words2/lang_ZH_HK.py +48 -0
- num2words2/lang_ZH_TW.py +198 -0
- num2words2/utils.py +35 -0
- num2words2-0.1.0.dev1.data/scripts/num2words2 +98 -0
- num2words2-0.1.0.dev1.dist-info/METADATA +244 -0
- num2words2-0.1.0.dev1.dist-info/RECORD +133 -0
- num2words2-0.1.0.dev1.dist-info/WHEEL +5 -0
- num2words2-0.1.0.dev1.dist-info/entry_points.txt +2 -0
- num2words2-0.1.0.dev1.dist-info/licenses/COPYING +145 -0
- num2words2-0.1.0.dev1.dist-info/top_level.txt +1 -0
num2words2/lang_SA.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
|
3
|
+
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
# This library is free software; you can redistribute it and/or
|
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
7
|
+
# License as published by the Free Software Foundation; either
|
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# Lesser General Public License for more details.
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
14
|
+
# License along with this library; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
16
|
+
# MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
from __future__ import unicode_literals
|
|
19
|
+
|
|
20
|
+
from .base import Num2Word_Base
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Sanskrit language support
|
|
24
|
+
class Num2Word_SA(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'INR': (('रूप्यकाणि', 'रूप्यकाणि'), ('पैसा', 'पैसा')),
|
|
27
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents')),
|
|
28
|
+
'EUR': (('euro', 'euros'), ('cent', 'cents'))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def setup(self):
|
|
32
|
+
self.negword = "minus "
|
|
33
|
+
self.pointword = "point"
|
|
34
|
+
self.ones = ['', 'एकम्', 'द्वे', 'त्रीणि', 'चत्वारि', 'पञ्च', 'षट्', 'सप्त', 'अष्ट', 'नव']
|
|
35
|
+
self.tens = ['', 'दश', 'विंशति', 'त्रिंशत्', 'चत्वारिंशत्', 'पञ्चाशत्', 'षष्टि', 'सप्तति', 'अशीति', 'नवति']
|
|
36
|
+
self.hundred = "शतम्"
|
|
37
|
+
self.thousand = "सहस्रम्"
|
|
38
|
+
self.million = "दशलक्षम्"
|
|
39
|
+
|
|
40
|
+
def to_cardinal(self, number):
|
|
41
|
+
"""Convert a number to its word representation in Sanskrit."""
|
|
42
|
+
n = str(number).strip()
|
|
43
|
+
|
|
44
|
+
if n.startswith('-'):
|
|
45
|
+
n = n[1:]
|
|
46
|
+
ret = self.negword
|
|
47
|
+
else:
|
|
48
|
+
ret = ""
|
|
49
|
+
|
|
50
|
+
if '.' in n:
|
|
51
|
+
left, right = n.split('.', 1)
|
|
52
|
+
ret += self._int_to_word(int(left)) + " " + self.pointword + " "
|
|
53
|
+
for digit in right:
|
|
54
|
+
ret += self._int_to_word(int(digit)) + " "
|
|
55
|
+
return ret.strip()
|
|
56
|
+
else:
|
|
57
|
+
return (ret + self._int_to_word(int(n))).strip()
|
|
58
|
+
|
|
59
|
+
def _int_to_word(self, number):
|
|
60
|
+
"""Convert an integer to its word representation in Sanskrit."""
|
|
61
|
+
if number == 0:
|
|
62
|
+
return self.ones[0] if self.ones[0] else "zero"
|
|
63
|
+
|
|
64
|
+
if number < 0:
|
|
65
|
+
return self.negword + self._int_to_word(abs(number))
|
|
66
|
+
elif number < 10:
|
|
67
|
+
return self.ones[number]
|
|
68
|
+
elif number < 100:
|
|
69
|
+
tens_val = number // 10
|
|
70
|
+
ones_val = number % 10
|
|
71
|
+
if ones_val == 0:
|
|
72
|
+
return self.tens[tens_val]
|
|
73
|
+
else:
|
|
74
|
+
return self.tens[tens_val] + " " + self.ones[ones_val]
|
|
75
|
+
elif number < 1000:
|
|
76
|
+
hundreds_val = number // 100
|
|
77
|
+
remainder = number % 100
|
|
78
|
+
result = self.ones[hundreds_val] + " " + self.hundred
|
|
79
|
+
if remainder:
|
|
80
|
+
result += " " + self._int_to_word(remainder)
|
|
81
|
+
return result
|
|
82
|
+
elif number < 1000000:
|
|
83
|
+
thousands_val = number // 1000
|
|
84
|
+
remainder = number % 1000
|
|
85
|
+
result = self._int_to_word(thousands_val) + " " + self.thousand
|
|
86
|
+
if remainder:
|
|
87
|
+
result += " " + self._int_to_word(remainder)
|
|
88
|
+
return result
|
|
89
|
+
elif number < 1000000000:
|
|
90
|
+
millions_val = number // 1000000
|
|
91
|
+
remainder = number % 1000000
|
|
92
|
+
result = self._int_to_word(millions_val) + " " + self.million
|
|
93
|
+
if remainder:
|
|
94
|
+
result += " " + self._int_to_word(remainder)
|
|
95
|
+
return result
|
|
96
|
+
else:
|
|
97
|
+
return str(number) # Fallback for very large numbers
|
|
98
|
+
|
|
99
|
+
def to_ordinal(self, number):
|
|
100
|
+
"""Convert to ordinal in Sanskrit."""
|
|
101
|
+
cardinal = self.to_cardinal(number)
|
|
102
|
+
# Language-specific ordinal suffix
|
|
103
|
+
return cardinal + "-मः"
|
|
104
|
+
|
|
105
|
+
def to_ordinal_num(self, number):
|
|
106
|
+
"""Convert to abbreviated ordinal."""
|
|
107
|
+
return str(number) + "."
|
|
108
|
+
|
|
109
|
+
def to_year(self, val, longval=True):
|
|
110
|
+
"""Convert to year in Sanskrit."""
|
|
111
|
+
return self.to_cardinal(val)
|
|
112
|
+
|
|
113
|
+
def to_currency(self, val, currency='INR', cents=True, separator=' ', adjective=False):
|
|
114
|
+
"""Convert to currency in Sanskrit."""
|
|
115
|
+
is_negative = False
|
|
116
|
+
if val < 0:
|
|
117
|
+
is_negative = True
|
|
118
|
+
val = abs(val)
|
|
119
|
+
|
|
120
|
+
parts = str(val).split('.')
|
|
121
|
+
left = int(parts[0]) if parts[0] else 0
|
|
122
|
+
right = int(parts[1][:2].ljust(2, '0')) if len(parts) > 1 and parts[1] else 0
|
|
123
|
+
|
|
124
|
+
cr1, cr2 = self.CURRENCY_FORMS.get(currency, list(self.CURRENCY_FORMS.values())[0])
|
|
125
|
+
|
|
126
|
+
left_str = self._int_to_word(left)
|
|
127
|
+
result = left_str + " " + (cr1[1] if left != 1 else cr1[0])
|
|
128
|
+
|
|
129
|
+
if cents and right:
|
|
130
|
+
cents_str = self._int_to_word(right)
|
|
131
|
+
result += separator + cents_str + " " + (cr2[1] if right != 1 else cr2[0])
|
|
132
|
+
|
|
133
|
+
if is_negative:
|
|
134
|
+
result = self.negword + result
|
|
135
|
+
|
|
136
|
+
return result.strip()
|
num2words2/lang_SD.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
|
3
|
+
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
# This library is free software; you can redistribute it and/or
|
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
7
|
+
# License as published by the Free Software Foundation; either
|
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# Lesser General Public License for more details.
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
14
|
+
# License along with this library; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
16
|
+
# MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
from __future__ import unicode_literals
|
|
19
|
+
|
|
20
|
+
from .base import Num2Word_Base
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Sindhi language support
|
|
24
|
+
class Num2Word_SD(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'PKR': (('روپي', 'روپيا'), ('پئسو', 'پئسا')),
|
|
27
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents')),
|
|
28
|
+
'EUR': (('euro', 'euros'), ('cent', 'cents'))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def setup(self):
|
|
32
|
+
self.negword = "minus "
|
|
33
|
+
self.pointword = "point"
|
|
34
|
+
self.ones = ['', 'هڪ', 'ٻه', 'ٽي', 'چار', 'پنج', 'ڇهه', 'ست', 'اٺ', 'نو']
|
|
35
|
+
self.tens = ['', 'ڏهه', 'ويهه', 'ٽيهه', 'چاليهه', 'پنجاهه', 'سٺ', 'ستر', 'اسي', 'نوي']
|
|
36
|
+
self.hundred = "سو"
|
|
37
|
+
self.thousand = "هزار"
|
|
38
|
+
self.million = "لک"
|
|
39
|
+
|
|
40
|
+
def to_cardinal(self, number):
|
|
41
|
+
"""Convert a number to its word representation in Sindhi."""
|
|
42
|
+
n = str(number).strip()
|
|
43
|
+
|
|
44
|
+
if n.startswith('-'):
|
|
45
|
+
n = n[1:]
|
|
46
|
+
ret = self.negword
|
|
47
|
+
else:
|
|
48
|
+
ret = ""
|
|
49
|
+
|
|
50
|
+
if '.' in n:
|
|
51
|
+
left, right = n.split('.', 1)
|
|
52
|
+
ret += self._int_to_word(int(left)) + " " + self.pointword + " "
|
|
53
|
+
for digit in right:
|
|
54
|
+
ret += self._int_to_word(int(digit)) + " "
|
|
55
|
+
return ret.strip()
|
|
56
|
+
else:
|
|
57
|
+
return (ret + self._int_to_word(int(n))).strip()
|
|
58
|
+
|
|
59
|
+
def _int_to_word(self, number):
|
|
60
|
+
"""Convert an integer to its word representation in Sindhi."""
|
|
61
|
+
if number == 0:
|
|
62
|
+
return self.ones[0] if self.ones[0] else "zero"
|
|
63
|
+
|
|
64
|
+
if number < 0:
|
|
65
|
+
return self.negword + self._int_to_word(abs(number))
|
|
66
|
+
elif number < 10:
|
|
67
|
+
return self.ones[number]
|
|
68
|
+
elif number < 100:
|
|
69
|
+
tens_val = number // 10
|
|
70
|
+
ones_val = number % 10
|
|
71
|
+
if ones_val == 0:
|
|
72
|
+
return self.tens[tens_val]
|
|
73
|
+
else:
|
|
74
|
+
return self.tens[tens_val] + " " + self.ones[ones_val]
|
|
75
|
+
elif number < 1000:
|
|
76
|
+
hundreds_val = number // 100
|
|
77
|
+
remainder = number % 100
|
|
78
|
+
result = self.ones[hundreds_val] + " " + self.hundred
|
|
79
|
+
if remainder:
|
|
80
|
+
result += " " + self._int_to_word(remainder)
|
|
81
|
+
return result
|
|
82
|
+
elif number < 1000000:
|
|
83
|
+
thousands_val = number // 1000
|
|
84
|
+
remainder = number % 1000
|
|
85
|
+
result = self._int_to_word(thousands_val) + " " + self.thousand
|
|
86
|
+
if remainder:
|
|
87
|
+
result += " " + self._int_to_word(remainder)
|
|
88
|
+
return result
|
|
89
|
+
elif number < 1000000000:
|
|
90
|
+
millions_val = number // 1000000
|
|
91
|
+
remainder = number % 1000000
|
|
92
|
+
result = self._int_to_word(millions_val) + " " + self.million
|
|
93
|
+
if remainder:
|
|
94
|
+
result += " " + self._int_to_word(remainder)
|
|
95
|
+
return result
|
|
96
|
+
else:
|
|
97
|
+
return str(number) # Fallback for very large numbers
|
|
98
|
+
|
|
99
|
+
def to_ordinal(self, number):
|
|
100
|
+
"""Convert to ordinal in Sindhi."""
|
|
101
|
+
cardinal = self.to_cardinal(number)
|
|
102
|
+
# Language-specific ordinal suffix
|
|
103
|
+
return cardinal + "-و"
|
|
104
|
+
|
|
105
|
+
def to_ordinal_num(self, number):
|
|
106
|
+
"""Convert to abbreviated ordinal."""
|
|
107
|
+
return str(number) + "."
|
|
108
|
+
|
|
109
|
+
def to_year(self, val, longval=True):
|
|
110
|
+
"""Convert to year in Sindhi."""
|
|
111
|
+
return self.to_cardinal(val)
|
|
112
|
+
|
|
113
|
+
def to_currency(self, val, currency='PKR', cents=True, separator=' ', adjective=False):
|
|
114
|
+
"""Convert to currency in Sindhi."""
|
|
115
|
+
is_negative = False
|
|
116
|
+
if val < 0:
|
|
117
|
+
is_negative = True
|
|
118
|
+
val = abs(val)
|
|
119
|
+
|
|
120
|
+
parts = str(val).split('.')
|
|
121
|
+
left = int(parts[0]) if parts[0] else 0
|
|
122
|
+
right = int(parts[1][:2].ljust(2, '0')) if len(parts) > 1 and parts[1] else 0
|
|
123
|
+
|
|
124
|
+
cr1, cr2 = self.CURRENCY_FORMS.get(currency, list(self.CURRENCY_FORMS.values())[0])
|
|
125
|
+
|
|
126
|
+
left_str = self._int_to_word(left)
|
|
127
|
+
result = left_str + " " + (cr1[1] if left != 1 else cr1[0])
|
|
128
|
+
|
|
129
|
+
if cents and right:
|
|
130
|
+
cents_str = self._int_to_word(right)
|
|
131
|
+
result += separator + cents_str + " " + (cr2[1] if right != 1 else cr2[0])
|
|
132
|
+
|
|
133
|
+
if is_negative:
|
|
134
|
+
result = self.negword + result
|
|
135
|
+
|
|
136
|
+
return result.strip()
|
num2words2/lang_SI.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
|
3
|
+
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
# This library is free software; you can redistribute it and/or
|
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
7
|
+
# License as published by the Free Software Foundation; either
|
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# Lesser General Public License for more details.
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
14
|
+
# License along with this library; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
16
|
+
# MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
from __future__ import unicode_literals
|
|
19
|
+
|
|
20
|
+
from .base import Num2Word_Base
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Sinhala language support
|
|
24
|
+
class Num2Word_SI(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'LKR': (('රුපියල්', 'රුපියල්'), ('සත', 'සත')),
|
|
27
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents')),
|
|
28
|
+
'EUR': (('euro', 'euros'), ('cent', 'cents')),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def setup(self):
|
|
32
|
+
self.negword = "minus "
|
|
33
|
+
self.pointword = "point"
|
|
34
|
+
self.ones = ['', 'එක', 'දෙක', 'තුන', 'හතර', 'පහ', 'හය', 'හත', 'අට', 'නවය']
|
|
35
|
+
self.tens = ['', 'දහය', 'විස්ස', 'තිහ', 'හතළිහ', 'පනහ', 'හැට', 'හැත්තෑව', 'අසූව', 'අනූව']
|
|
36
|
+
self.hundred = 'සියය'
|
|
37
|
+
self.thousand = 'දහස'
|
|
38
|
+
self.lakh = 'ලක්ෂය'
|
|
39
|
+
self.crore = 'කෝටිය'
|
|
40
|
+
|
|
41
|
+
def to_cardinal(self, number):
|
|
42
|
+
"""Convert a number to its word representation in Sinhala."""
|
|
43
|
+
n = str(number).strip()
|
|
44
|
+
|
|
45
|
+
if n.startswith('-'):
|
|
46
|
+
n = n[1:]
|
|
47
|
+
ret = self.negword
|
|
48
|
+
else:
|
|
49
|
+
ret = ""
|
|
50
|
+
|
|
51
|
+
if '.' in n:
|
|
52
|
+
left, right = n.split('.', 1)
|
|
53
|
+
ret += self._int_to_word(int(left)) + " " + self.pointword + " "
|
|
54
|
+
for digit in right:
|
|
55
|
+
ret += self._int_to_word(int(digit)) + " "
|
|
56
|
+
return ret.strip()
|
|
57
|
+
else:
|
|
58
|
+
return (ret + self._int_to_word(int(n))).strip()
|
|
59
|
+
|
|
60
|
+
def _int_to_word(self, number):
|
|
61
|
+
"""Convert an integer to its word representation in Sinhala."""
|
|
62
|
+
if number == 0:
|
|
63
|
+
return self.ones[0] if self.ones[0] else "බිංදුව"
|
|
64
|
+
|
|
65
|
+
if number < 0:
|
|
66
|
+
return self.negword + self._int_to_word(abs(number))
|
|
67
|
+
elif number < 10:
|
|
68
|
+
return self.ones[number]
|
|
69
|
+
elif number < 100:
|
|
70
|
+
tens_val = number // 10
|
|
71
|
+
ones_val = number % 10
|
|
72
|
+
if ones_val == 0:
|
|
73
|
+
return self.tens[tens_val]
|
|
74
|
+
else:
|
|
75
|
+
return self.tens[tens_val] + " " + self.ones[ones_val]
|
|
76
|
+
elif number < 1000:
|
|
77
|
+
hundreds_val = number // 100
|
|
78
|
+
remainder = number % 100
|
|
79
|
+
if hundreds_val == 1:
|
|
80
|
+
result = self.hundred
|
|
81
|
+
else:
|
|
82
|
+
result = self.ones[hundreds_val] + " " + self.hundred
|
|
83
|
+
if remainder:
|
|
84
|
+
result += " " + self._int_to_word(remainder)
|
|
85
|
+
return result
|
|
86
|
+
elif number < 100000:
|
|
87
|
+
thousands_val = number // 1000
|
|
88
|
+
remainder = number % 1000
|
|
89
|
+
if thousands_val == 1:
|
|
90
|
+
result = self.thousand
|
|
91
|
+
else:
|
|
92
|
+
result = self._int_to_word(thousands_val) + " " + self.thousand
|
|
93
|
+
if remainder:
|
|
94
|
+
result += " " + self._int_to_word(remainder)
|
|
95
|
+
return result
|
|
96
|
+
elif number < 10000000:
|
|
97
|
+
lakh_val = number // 100000
|
|
98
|
+
remainder = number % 100000
|
|
99
|
+
if lakh_val == 1:
|
|
100
|
+
result = self.lakh
|
|
101
|
+
else:
|
|
102
|
+
result = self._int_to_word(lakh_val) + " " + self.lakh
|
|
103
|
+
if remainder:
|
|
104
|
+
result += " " + self._int_to_word(remainder)
|
|
105
|
+
return result
|
|
106
|
+
elif number < 1000000000:
|
|
107
|
+
crore_val = number // 10000000
|
|
108
|
+
remainder = number % 10000000
|
|
109
|
+
if crore_val == 1:
|
|
110
|
+
result = self.crore
|
|
111
|
+
else:
|
|
112
|
+
result = self._int_to_word(crore_val) + " " + self.crore
|
|
113
|
+
if remainder:
|
|
114
|
+
result += " " + self._int_to_word(remainder)
|
|
115
|
+
return result
|
|
116
|
+
else:
|
|
117
|
+
return str(number) # Fallback for very large numbers
|
|
118
|
+
|
|
119
|
+
def to_ordinal(self, number):
|
|
120
|
+
"""Convert to ordinal in Sinhala."""
|
|
121
|
+
# Basic implementation with වැනි suffix
|
|
122
|
+
return self.to_cardinal(number) + " වැනි"
|
|
123
|
+
|
|
124
|
+
def to_ordinal_num(self, number):
|
|
125
|
+
"""Convert to abbreviated ordinal."""
|
|
126
|
+
return str(number) + "."
|
|
127
|
+
|
|
128
|
+
def to_year(self, val, longval=True):
|
|
129
|
+
"""Convert to year."""
|
|
130
|
+
return self.to_cardinal(val)
|
|
131
|
+
|
|
132
|
+
def to_currency(self, val, currency='LKR', cents=True, separator=' ', adjective=False):
|
|
133
|
+
"""Convert to currency in Sinhala."""
|
|
134
|
+
is_negative = False
|
|
135
|
+
if val < 0:
|
|
136
|
+
is_negative = True
|
|
137
|
+
val = abs(val)
|
|
138
|
+
|
|
139
|
+
parts = str(val).split('.')
|
|
140
|
+
left = int(parts[0]) if parts[0] else 0
|
|
141
|
+
right = int(parts[1][:2].ljust(2, '0')) if len(parts) > 1 and parts[1] else 0
|
|
142
|
+
|
|
143
|
+
cr1, cr2 = self.CURRENCY_FORMS.get(currency, self.CURRENCY_FORMS['LKR'])
|
|
144
|
+
|
|
145
|
+
left_str = self.to_cardinal(left)
|
|
146
|
+
result = left_str + " " + (cr1[1] if left != 1 else cr1[0])
|
|
147
|
+
|
|
148
|
+
if cents and right:
|
|
149
|
+
cents_str = self.to_cardinal(right)
|
|
150
|
+
result += separator + cents_str + " " + (cr2[1] if right != 1 else cr2[0])
|
|
151
|
+
|
|
152
|
+
return (self.negword if is_negative else "") + result
|
num2words2/lang_SK.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
# This library is free software; you can redistribute it and/or
|
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
6
|
+
# License as published by the Free Software Foundation; either
|
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
11
|
+
# Lesser General Public License for more details.
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
13
|
+
# License along with this library; if not, write to the Free Software
|
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
15
|
+
# MA 02110-1301 USA
|
|
16
|
+
|
|
17
|
+
from __future__ import unicode_literals
|
|
18
|
+
|
|
19
|
+
from .base import Num2Word_Base
|
|
20
|
+
from .utils import get_digits, splitbyx
|
|
21
|
+
|
|
22
|
+
ZERO = ('nula',)
|
|
23
|
+
|
|
24
|
+
ONES = {
|
|
25
|
+
1: ('jeden', 'jeden', set()),
|
|
26
|
+
2: ('dva', 'dve', {1, 3, 5, 7, 9}),
|
|
27
|
+
3: ('tri', 'tri', set()),
|
|
28
|
+
4: ('štyri', 'štyri', set()),
|
|
29
|
+
5: ('päť', 'päť', set()),
|
|
30
|
+
6: ('šesť', 'šesť', set()),
|
|
31
|
+
7: ('sedem', 'sedem', set()),
|
|
32
|
+
8: ('osem', 'osem', set()),
|
|
33
|
+
9: ('deväť', 'deväť', set()),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
TENS = {
|
|
37
|
+
0: ('desať',),
|
|
38
|
+
1: ('jedenásť',),
|
|
39
|
+
2: ('dvanásť',),
|
|
40
|
+
3: ('trinásť',),
|
|
41
|
+
4: ('štrnásť',),
|
|
42
|
+
5: ('pätnásť',),
|
|
43
|
+
6: ('šestnásť',),
|
|
44
|
+
7: ('sedemnásť',),
|
|
45
|
+
8: ('osemnásť',),
|
|
46
|
+
9: ('devätnásť',),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
TWENTIES = {
|
|
50
|
+
2: ('dvadsať',),
|
|
51
|
+
3: ('tridsať',),
|
|
52
|
+
4: ('štyridsať',),
|
|
53
|
+
5: ('päťdesiat',),
|
|
54
|
+
6: ('šesťdesiat',),
|
|
55
|
+
7: ('sedemdesiat',),
|
|
56
|
+
8: ('osemdesiat',),
|
|
57
|
+
9: ('deväťdesiat',),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
HUNDREDS = {
|
|
61
|
+
1: ('sto',),
|
|
62
|
+
2: ('dvesto',),
|
|
63
|
+
3: ('tristo',),
|
|
64
|
+
4: ('štyristo',),
|
|
65
|
+
5: ('päťsto',),
|
|
66
|
+
6: ('šesťsto',),
|
|
67
|
+
7: ('sedemsto',),
|
|
68
|
+
8: ('osemsto',),
|
|
69
|
+
9: ('deväťsto',),
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
THOUSANDS = {
|
|
73
|
+
1: ('tisíc', 'tisíc', 'tisíc'), # 10^3
|
|
74
|
+
2: ('milión', 'milióny', 'miliónov'), # 10^6
|
|
75
|
+
3: ('miliarda', 'miliardy', 'miliárd'), # 10^9
|
|
76
|
+
4: ('bilión', 'bilióny', 'biliónov'), # 10^12
|
|
77
|
+
5: ('biliarda', 'biliardy', 'biliárd'), # 10^15
|
|
78
|
+
6: ('trilión', 'trilióny', 'triliónov'), # 10^18
|
|
79
|
+
7: ('triliarda', 'triliardy', 'triliárd'), # 10^21
|
|
80
|
+
8: ('kvadrilión', 'kvadrilióny', 'kvadriliónov'), # 10^24
|
|
81
|
+
9: ('kvadriliarda', 'kvadriliardy', 'kvadriliárd'), # 10^27
|
|
82
|
+
10: ('kvintilión', 'kvintillióny', 'kvintiliónov'), # 10^30
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class Num2Word_SK(Num2Word_Base):
|
|
87
|
+
CURRENCY_FORMS = {
|
|
88
|
+
'EUR': (
|
|
89
|
+
('euro', 'eurá', 'eur'), ('cent', 'centy', 'centov')
|
|
90
|
+
),
|
|
91
|
+
'CZK': (
|
|
92
|
+
('koruna', 'koruny', 'korún'), ('halier', 'haliere', 'halierov')
|
|
93
|
+
),
|
|
94
|
+
'USD': (
|
|
95
|
+
('dolár', 'doláre', 'dolárov'), ('cent', 'centy', 'centov')
|
|
96
|
+
),
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
def setup(self):
|
|
100
|
+
self.negword = "mínus"
|
|
101
|
+
self.pointword = "celých"
|
|
102
|
+
|
|
103
|
+
def to_cardinal(self, number):
|
|
104
|
+
n = str(number).replace(',', '.')
|
|
105
|
+
if '.' in n:
|
|
106
|
+
is_negative = n.startswith('-')
|
|
107
|
+
abs_n = n[1:] if is_negative else n
|
|
108
|
+
left, right = abs_n.split('.')
|
|
109
|
+
leading_zero_count = len(right) - len(right.lstrip('0'))
|
|
110
|
+
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
|
|
111
|
+
self._int2word(int(right)))
|
|
112
|
+
result = u'%s %s %s' % (
|
|
113
|
+
self._int2word(int(left)),
|
|
114
|
+
self.pointword,
|
|
115
|
+
decimal_part
|
|
116
|
+
)
|
|
117
|
+
if is_negative:
|
|
118
|
+
result = self.negword + ' ' + result
|
|
119
|
+
return result
|
|
120
|
+
else:
|
|
121
|
+
# Handle negative integers
|
|
122
|
+
is_negative = n.startswith('-')
|
|
123
|
+
if is_negative:
|
|
124
|
+
abs_n = n[1:]
|
|
125
|
+
result = self._int2word(int(abs_n))
|
|
126
|
+
return self.negword + ' ' + result
|
|
127
|
+
else:
|
|
128
|
+
return self._int2word(int(n))
|
|
129
|
+
|
|
130
|
+
def pluralize(self, n, forms):
|
|
131
|
+
if n == 1:
|
|
132
|
+
form = 0
|
|
133
|
+
elif 0 < n < 5:
|
|
134
|
+
form = 1
|
|
135
|
+
else:
|
|
136
|
+
form = 2
|
|
137
|
+
return forms[form]
|
|
138
|
+
|
|
139
|
+
def to_currency(self, val, currency='EUR', cents=True, separator=',',
|
|
140
|
+
adjective=False):
|
|
141
|
+
# Handle integers specially - just add currency name without cents
|
|
142
|
+
if isinstance(val, int):
|
|
143
|
+
try:
|
|
144
|
+
cr1, cr2 = self.CURRENCY_FORMS[currency]
|
|
145
|
+
except (KeyError, AttributeError):
|
|
146
|
+
# Fallback to base implementation for unknown currency
|
|
147
|
+
return super(Num2Word_SK, self).to_currency(
|
|
148
|
+
val, currency=currency, cents=cents, separator=separator,
|
|
149
|
+
adjective=adjective)
|
|
150
|
+
|
|
151
|
+
minus_str = self.negword if val < 0 else ""
|
|
152
|
+
abs_val = abs(val)
|
|
153
|
+
money_str = self.to_cardinal(abs_val)
|
|
154
|
+
|
|
155
|
+
# Proper pluralization for currency
|
|
156
|
+
if abs_val == 1:
|
|
157
|
+
currency_str = cr1[0] if isinstance(cr1, tuple) else cr1
|
|
158
|
+
else:
|
|
159
|
+
currency_str = cr1[1] if isinstance(cr1, tuple) and len(cr1) > 1 else (cr1[0] if isinstance(cr1, tuple) else cr1)
|
|
160
|
+
|
|
161
|
+
return (u'%s %s %s' % (minus_str, money_str, currency_str)).strip()
|
|
162
|
+
|
|
163
|
+
# For floats, use the parent class implementation
|
|
164
|
+
return super(Num2Word_SK, self).to_currency(
|
|
165
|
+
val, currency=currency, cents=cents, separator=separator,
|
|
166
|
+
adjective=adjective)
|
|
167
|
+
|
|
168
|
+
def to_ordinal(self, number):
|
|
169
|
+
"""Convert to Slovak ordinal numbers."""
|
|
170
|
+
try:
|
|
171
|
+
num = int(number)
|
|
172
|
+
except (ValueError, TypeError):
|
|
173
|
+
return str(number)
|
|
174
|
+
|
|
175
|
+
# Slovak ordinals
|
|
176
|
+
ordinals = {
|
|
177
|
+
1: 'prvý',
|
|
178
|
+
2: 'druhý',
|
|
179
|
+
3: 'tretí',
|
|
180
|
+
4: 'štvrtý',
|
|
181
|
+
5: 'piaty',
|
|
182
|
+
6: 'šiesty',
|
|
183
|
+
7: 'siedmy',
|
|
184
|
+
8: 'ôsmy',
|
|
185
|
+
9: 'deviaty',
|
|
186
|
+
10: 'desiaty',
|
|
187
|
+
11: 'jedenásty',
|
|
188
|
+
12: 'dvanásty',
|
|
189
|
+
13: 'trinásty',
|
|
190
|
+
14: 'štrnásty',
|
|
191
|
+
15: 'pätnásty',
|
|
192
|
+
16: 'šestnásty',
|
|
193
|
+
17: 'sedemnásty',
|
|
194
|
+
18: 'osemnásty',
|
|
195
|
+
19: 'devätnásty',
|
|
196
|
+
20: 'dvadsiaty',
|
|
197
|
+
30: 'tridsiaty',
|
|
198
|
+
40: 'štyridsiaty',
|
|
199
|
+
50: 'päťdesiaty',
|
|
200
|
+
60: 'šesťdesiaty',
|
|
201
|
+
70: 'sedemdesiaty',
|
|
202
|
+
80: 'osemdesiaty',
|
|
203
|
+
90: 'deväťdesiaty',
|
|
204
|
+
100: 'stý',
|
|
205
|
+
1000: 'tisíci',
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if num in ordinals:
|
|
209
|
+
return ordinals[num]
|
|
210
|
+
|
|
211
|
+
# For other numbers, add 'ý' suffix to the cardinal
|
|
212
|
+
# This is a simplified implementation
|
|
213
|
+
cardinal = self.to_cardinal(num)
|
|
214
|
+
return cardinal + 'ý'
|
|
215
|
+
|
|
216
|
+
def _int2word(self, n):
|
|
217
|
+
if n == 0:
|
|
218
|
+
return ZERO[0]
|
|
219
|
+
|
|
220
|
+
words = []
|
|
221
|
+
chunks = list(splitbyx(str(n), 3))
|
|
222
|
+
i = len(chunks)
|
|
223
|
+
for x in chunks:
|
|
224
|
+
i -= 1
|
|
225
|
+
|
|
226
|
+
if x == 0:
|
|
227
|
+
continue
|
|
228
|
+
|
|
229
|
+
n1, n2, n3 = get_digits(x)
|
|
230
|
+
|
|
231
|
+
word_chunk = []
|
|
232
|
+
|
|
233
|
+
if n3 > 0:
|
|
234
|
+
word_chunk.append(HUNDREDS[n3][0])
|
|
235
|
+
|
|
236
|
+
if n2 > 1:
|
|
237
|
+
word_chunk.append(TWENTIES[n2][0])
|
|
238
|
+
|
|
239
|
+
if n2 == 1:
|
|
240
|
+
word_chunk.append(TENS[n1][0])
|
|
241
|
+
elif n1 > 0 and not (i > 0 and x == 1):
|
|
242
|
+
if n2 == 0 and n3 == 0 and i in ONES[n1][2]:
|
|
243
|
+
word_chunk.append(ONES[n1][1])
|
|
244
|
+
else:
|
|
245
|
+
word_chunk.append(ONES[n1][0])
|
|
246
|
+
if i > 0:
|
|
247
|
+
word_chunk.append(self.pluralize(x, THOUSANDS[i]))
|
|
248
|
+
words.append(' '.join(word_chunk))
|
|
249
|
+
|
|
250
|
+
return ' '.join(words)
|