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_LT.py
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
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
|
+
from .utils import get_digits, splitbyx
|
|
22
|
+
|
|
23
|
+
ZERO = ('nulis',)
|
|
24
|
+
|
|
25
|
+
ONES_FEMININE = {
|
|
26
|
+
1: ('viena',),
|
|
27
|
+
2: ('dvi',),
|
|
28
|
+
3: ('trys',),
|
|
29
|
+
4: ('keturios',),
|
|
30
|
+
5: ('penkios',),
|
|
31
|
+
6: ('šešios',),
|
|
32
|
+
7: ('septynios',),
|
|
33
|
+
8: ('aštuonios',),
|
|
34
|
+
9: ('devynios',),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ONES = {
|
|
38
|
+
1: ('vienas',),
|
|
39
|
+
2: ('du',),
|
|
40
|
+
3: ('trys',),
|
|
41
|
+
4: ('keturi',),
|
|
42
|
+
5: ('penki',),
|
|
43
|
+
6: ('šeši',),
|
|
44
|
+
7: ('septyni',),
|
|
45
|
+
8: ('aštuoni',),
|
|
46
|
+
9: ('devyni',),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
TENS = {
|
|
50
|
+
0: ('dešimt',),
|
|
51
|
+
1: ('vienuolika',),
|
|
52
|
+
2: ('dvylika',),
|
|
53
|
+
3: ('trylika',),
|
|
54
|
+
4: ('keturiolika',),
|
|
55
|
+
5: ('penkiolika',),
|
|
56
|
+
6: ('šešiolika',),
|
|
57
|
+
7: ('septyniolika',),
|
|
58
|
+
8: ('aštuoniolika',),
|
|
59
|
+
9: ('devyniolika',),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
TWENTIES = {
|
|
63
|
+
2: ('dvidešimt',),
|
|
64
|
+
3: ('trisdešimt',),
|
|
65
|
+
4: ('keturiasdešimt',),
|
|
66
|
+
5: ('penkiasdešimt',),
|
|
67
|
+
6: ('šešiasdešimt',),
|
|
68
|
+
7: ('septyniasdešimt',),
|
|
69
|
+
8: ('aštuoniasdešimt',),
|
|
70
|
+
9: ('devyniasdešimt',),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
HUNDRED = ('šimtas', 'šimtai')
|
|
74
|
+
|
|
75
|
+
THOUSANDS = {
|
|
76
|
+
1: ('tūkstantis', 'tūkstančiai', 'tūkstančių'),
|
|
77
|
+
2: ('milijonas', 'milijonai', 'milijonų'),
|
|
78
|
+
3: ('milijardas', 'milijardai', 'milijardų'),
|
|
79
|
+
4: ('trilijonas', 'trilijonai', 'trilijonų'),
|
|
80
|
+
5: ('kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'),
|
|
81
|
+
6: ('kvintilijonas', 'kvintilijonai', 'kvintilijonų'),
|
|
82
|
+
7: ('sikstilijonas', 'sikstilijonai', 'sikstilijonų'),
|
|
83
|
+
8: ('septilijonas', 'septilijonai', 'septilijonų'),
|
|
84
|
+
9: ('oktilijonas', 'oktilijonai', 'oktilijonų'),
|
|
85
|
+
10: ('naintilijonas', 'naintilijonai', 'naintilijonų'),
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
GENERIC_CENTS = ('centas', 'centai', 'centų')
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class Num2Word_LT(Num2Word_Base):
|
|
92
|
+
CURRENCY_FORMS = {
|
|
93
|
+
'LTL': (('litas', 'litai', 'litų'), GENERIC_CENTS),
|
|
94
|
+
'EUR': (('euras', 'eurai', 'eurų'), GENERIC_CENTS),
|
|
95
|
+
'USD': (('doleris', 'doleriai', 'dolerių'), GENERIC_CENTS),
|
|
96
|
+
'GBP': (
|
|
97
|
+
('svaras sterlingų', 'svarai sterlingų', 'svarų sterlingų'),
|
|
98
|
+
('pensas', 'pensai', 'pensų')
|
|
99
|
+
),
|
|
100
|
+
'PLN': (
|
|
101
|
+
('zlotas', 'zlotai', 'zlotų'),
|
|
102
|
+
('grašis', 'grašiai', 'grašių')),
|
|
103
|
+
'RUB': (
|
|
104
|
+
('rublis', 'rubliai', 'rublių'),
|
|
105
|
+
('kapeika', 'kapeikos', 'kapeikų')
|
|
106
|
+
),
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
def setup(self):
|
|
110
|
+
self.negword = "minus"
|
|
111
|
+
self.pointword = "kablelis"
|
|
112
|
+
|
|
113
|
+
def pluralize(self, n, forms):
|
|
114
|
+
n1, n2, n3 = get_digits(n)
|
|
115
|
+
if n2 == 1 or n1 == 0 or n == 0:
|
|
116
|
+
return forms[2]
|
|
117
|
+
elif n1 == 1:
|
|
118
|
+
return forms[0]
|
|
119
|
+
else:
|
|
120
|
+
return forms[1]
|
|
121
|
+
|
|
122
|
+
def to_cardinal(self, number):
|
|
123
|
+
n = str(number).replace(',', '.')
|
|
124
|
+
base_str, n = self.parse_minus(n)
|
|
125
|
+
if '.' in n:
|
|
126
|
+
left, right = n.split('.')
|
|
127
|
+
leading_zero_count = len(right) - len(right.lstrip('0'))
|
|
128
|
+
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
|
|
129
|
+
self._int2word(int(right)))
|
|
130
|
+
return '%s%s %s %s' % (
|
|
131
|
+
base_str,
|
|
132
|
+
self._int2word(int(left)),
|
|
133
|
+
self.pointword,
|
|
134
|
+
decimal_part
|
|
135
|
+
)
|
|
136
|
+
else:
|
|
137
|
+
return "%s%s" % (base_str, self._int2word(int(n)))
|
|
138
|
+
|
|
139
|
+
def to_ordinal(self, number):
|
|
140
|
+
"""Convert to Lithuanian ordinal numbers."""
|
|
141
|
+
try:
|
|
142
|
+
num = int(number)
|
|
143
|
+
except (ValueError, TypeError):
|
|
144
|
+
return str(number)
|
|
145
|
+
|
|
146
|
+
# Lithuanian ordinals
|
|
147
|
+
ordinals = {
|
|
148
|
+
1: 'pirmas',
|
|
149
|
+
2: 'antras',
|
|
150
|
+
3: 'trečias',
|
|
151
|
+
4: 'ketvirtas',
|
|
152
|
+
5: 'penktas',
|
|
153
|
+
6: 'šeštas',
|
|
154
|
+
7: 'septintas',
|
|
155
|
+
8: 'aštuntas',
|
|
156
|
+
9: 'devintas',
|
|
157
|
+
10: 'dešimtas',
|
|
158
|
+
11: 'vienuoliktas',
|
|
159
|
+
12: 'dvyliktas',
|
|
160
|
+
13: 'tryliktas',
|
|
161
|
+
14: 'keturioliktas',
|
|
162
|
+
15: 'penkioliktas',
|
|
163
|
+
16: 'šešioliktas',
|
|
164
|
+
17: 'septynioliktas',
|
|
165
|
+
18: 'aštuonioliktas',
|
|
166
|
+
19: 'devynioliktas',
|
|
167
|
+
20: 'dvidešimtas',
|
|
168
|
+
30: 'trisdešimtas',
|
|
169
|
+
40: 'keturiasdešimtas',
|
|
170
|
+
50: 'penkiasdešimtas',
|
|
171
|
+
60: 'šešiasdešimtas',
|
|
172
|
+
70: 'septyniasdešimtas',
|
|
173
|
+
80: 'aštuoniasdešimtas',
|
|
174
|
+
90: 'devyniasdešimtas',
|
|
175
|
+
100: 'šimtasis',
|
|
176
|
+
1000: 'tūkstantas',
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if num in ordinals:
|
|
180
|
+
return ordinals[num]
|
|
181
|
+
|
|
182
|
+
# For other numbers, add 'as' suffix to the cardinal
|
|
183
|
+
# This is a simplified implementation
|
|
184
|
+
cardinal = self.to_cardinal(num)
|
|
185
|
+
return cardinal + 'as'
|
|
186
|
+
|
|
187
|
+
def to_currency(self, val, currency='EUR', cents=True, separator='',
|
|
188
|
+
adjective=False):
|
|
189
|
+
if isinstance(val, int):
|
|
190
|
+
left = abs(val)
|
|
191
|
+
right = 0
|
|
192
|
+
is_negative = val < 0
|
|
193
|
+
is_float = False
|
|
194
|
+
else:
|
|
195
|
+
from decimal import Decimal
|
|
196
|
+
|
|
197
|
+
from .currency import parse_currency_parts
|
|
198
|
+
|
|
199
|
+
# Check if value has fractional cents
|
|
200
|
+
decimal_val = Decimal(str(val))
|
|
201
|
+
has_fractional_cents = (decimal_val * 100) % 1 != 0
|
|
202
|
+
|
|
203
|
+
left, right, is_negative = parse_currency_parts(val, is_int_with_cents=False,
|
|
204
|
+
keep_precision=has_fractional_cents)
|
|
205
|
+
is_float = True
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
cr1, cr2 = self.CURRENCY_FORMS[currency]
|
|
209
|
+
except KeyError:
|
|
210
|
+
raise NotImplementedError(
|
|
211
|
+
'Currency code "%s" not implemented for "%s"' %
|
|
212
|
+
(currency, self.__class__.__name__))
|
|
213
|
+
|
|
214
|
+
minus_str = "%s " % self.negword.strip() if is_negative else ""
|
|
215
|
+
money_str = self.to_cardinal(left)
|
|
216
|
+
|
|
217
|
+
# Show cents if right > 0 OR if input was a float (even if 0 cents)
|
|
218
|
+
if right > 0 or is_float:
|
|
219
|
+
if right == 0:
|
|
220
|
+
cents_str = self.to_cardinal(0) if cents else '0'
|
|
221
|
+
else:
|
|
222
|
+
# Handle fractional cents
|
|
223
|
+
from decimal import Decimal
|
|
224
|
+
if isinstance(right, Decimal):
|
|
225
|
+
# Convert fractional cents (e.g., 65.3 cents)
|
|
226
|
+
cents_str = self.to_cardinal_float(float(right)) if cents else str(float(right))
|
|
227
|
+
else:
|
|
228
|
+
cents_str = self.to_cardinal(right) if cents else str(right)
|
|
229
|
+
# Always add comma before cents if no separator specified
|
|
230
|
+
sep = separator if separator else ', '
|
|
231
|
+
return u'%s%s %s%s%s %s' % (
|
|
232
|
+
minus_str,
|
|
233
|
+
money_str,
|
|
234
|
+
self.pluralize(left, cr1),
|
|
235
|
+
sep,
|
|
236
|
+
cents_str,
|
|
237
|
+
self.pluralize(right, cr2)
|
|
238
|
+
)
|
|
239
|
+
else:
|
|
240
|
+
return u'%s%s %s' % (
|
|
241
|
+
minus_str,
|
|
242
|
+
money_str,
|
|
243
|
+
self.pluralize(left, cr1)
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
def _int2word(self, n, feminine=False):
|
|
247
|
+
if n == 0:
|
|
248
|
+
return ZERO[0]
|
|
249
|
+
|
|
250
|
+
words = []
|
|
251
|
+
chunks = list(splitbyx(str(n), 3))
|
|
252
|
+
i = len(chunks)
|
|
253
|
+
|
|
254
|
+
for x in chunks:
|
|
255
|
+
i -= 1
|
|
256
|
+
|
|
257
|
+
if x == 0:
|
|
258
|
+
continue
|
|
259
|
+
|
|
260
|
+
n1, n2, n3 = get_digits(x)
|
|
261
|
+
|
|
262
|
+
if n3 > 0:
|
|
263
|
+
words.append(ONES[n3][0])
|
|
264
|
+
if n3 > 1:
|
|
265
|
+
words.append(HUNDRED[1])
|
|
266
|
+
else:
|
|
267
|
+
words.append(HUNDRED[0])
|
|
268
|
+
|
|
269
|
+
if n2 > 1:
|
|
270
|
+
words.append(TWENTIES[n2][0])
|
|
271
|
+
|
|
272
|
+
if n2 == 1:
|
|
273
|
+
words.append(TENS[n1][0])
|
|
274
|
+
elif n1 > 0:
|
|
275
|
+
if (i == 1 or feminine and i == 0) and n < 1000:
|
|
276
|
+
words.append(ONES_FEMININE[n1][0])
|
|
277
|
+
else:
|
|
278
|
+
words.append(ONES[n1][0])
|
|
279
|
+
|
|
280
|
+
if i > 0:
|
|
281
|
+
words.append(self.pluralize(x, THOUSANDS[i]))
|
|
282
|
+
|
|
283
|
+
return ' '.join(words)
|
num2words2/lang_LV.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
from .utils import get_digits, splitbyx
|
|
22
|
+
|
|
23
|
+
ZERO = ('nulle',)
|
|
24
|
+
|
|
25
|
+
ONES = {
|
|
26
|
+
1: ('viens',),
|
|
27
|
+
2: ('divi',),
|
|
28
|
+
3: ('trīs',),
|
|
29
|
+
4: ('četri',),
|
|
30
|
+
5: ('pieci',),
|
|
31
|
+
6: ('seši',),
|
|
32
|
+
7: ('septiņi',),
|
|
33
|
+
8: ('astoņi',),
|
|
34
|
+
9: ('deviņi',),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
TENS = {
|
|
38
|
+
0: ('desmit',),
|
|
39
|
+
1: ('vienpadsmit',),
|
|
40
|
+
2: ('divpadsmit',),
|
|
41
|
+
3: ('trīspadsmit',),
|
|
42
|
+
4: ('četrpadsmit',),
|
|
43
|
+
5: ('piecpadsmit',),
|
|
44
|
+
6: ('sešpadsmit',),
|
|
45
|
+
7: ('septiņpadsmit',),
|
|
46
|
+
8: ('astoņpadsmit',),
|
|
47
|
+
9: ('deviņpadsmit',),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
TWENTIES = {
|
|
51
|
+
2: ('divdesmit',),
|
|
52
|
+
3: ('trīsdesmit',),
|
|
53
|
+
4: ('četrdesmit',),
|
|
54
|
+
5: ('piecdesmit',),
|
|
55
|
+
6: ('sešdesmit',),
|
|
56
|
+
7: ('septiņdesmit',),
|
|
57
|
+
8: ('astoņdesmit',),
|
|
58
|
+
9: ('deviņdesmit',),
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
HUNDRED = ('simts', 'simti', 'simtu')
|
|
62
|
+
|
|
63
|
+
THOUSANDS = {
|
|
64
|
+
1: ('tūkstotis', 'tūkstoši', 'tūkstošu'),
|
|
65
|
+
2: ('miljons', 'miljoni', 'miljonu'),
|
|
66
|
+
3: ('miljards', 'miljardi', 'miljardu'),
|
|
67
|
+
4: ('triljons', 'triljoni', 'triljonu'),
|
|
68
|
+
5: ('kvadriljons', 'kvadriljoni', 'kvadriljonu'),
|
|
69
|
+
6: ('kvintiljons', 'kvintiljoni', 'kvintiljonu'),
|
|
70
|
+
7: ('sikstiljons', 'sikstiljoni', 'sikstiljonu'),
|
|
71
|
+
8: ('septiljons', 'septiljoni', 'septiljonu'),
|
|
72
|
+
9: ('oktiljons', 'oktiljoni', 'oktiljonu'),
|
|
73
|
+
10: ('nontiljons', 'nontiljoni', 'nontiljonu'),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
GENERIC_DOLLARS = ('dolārs', 'dolāri', 'dolāru')
|
|
77
|
+
GENERIC_CENTS = ('cents', 'centi', 'centu')
|
|
78
|
+
|
|
79
|
+
GENERIC_KRONA = ('krona', 'kronas', 'kronu')
|
|
80
|
+
GENERIC_ERA = ('ēre', 'ēras', 'ēru')
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class Num2Word_LV(Num2Word_Base):
|
|
84
|
+
"""
|
|
85
|
+
Sadly we have a legal form (used in legal and finance documents):
|
|
86
|
+
http://www.eiro.lv/files/upload/files/Eiro_rakstiba-1.pdf
|
|
87
|
+
https://likumi.lv/doc.php?id=254741
|
|
88
|
+
http://eur-lex.europa.eu/legal-content/LV/TXT/HTML/?uri=CELEX:31998R0974&from=LV
|
|
89
|
+
|
|
90
|
+
Source: http://publications.europa.eu/code/lv/lv-5000500.htm
|
|
91
|
+
"""
|
|
92
|
+
CURRENCY_FORMS = {
|
|
93
|
+
'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
|
94
|
+
'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
|
95
|
+
# repalced by EUR
|
|
96
|
+
'EEK': (GENERIC_KRONA, GENERIC_CENTS),
|
|
97
|
+
'EUR': (('eiro', 'eiro', 'eiro'), GENERIC_CENTS),
|
|
98
|
+
'EUR_LEGAL': (('euro', 'euro', 'euro'), GENERIC_CENTS),
|
|
99
|
+
'GBP': (
|
|
100
|
+
('sterliņu mārciņa', 'sterliņu mārciņas', 'sterliņu mārciņu'),
|
|
101
|
+
('penss', 'pensi', 'pensu')),
|
|
102
|
+
# replaced by EUR
|
|
103
|
+
'LTL': (('lits', 'liti', 'litu'), GENERIC_CENTS),
|
|
104
|
+
# replaced by EUR
|
|
105
|
+
'LVL': (('lats', 'lati', 'latu'),
|
|
106
|
+
('santīms', 'santīmi', 'santīmu')),
|
|
107
|
+
'USD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
|
108
|
+
'RUB': (('rublis', 'rubļi', 'rubļu'),
|
|
109
|
+
('kapeika', 'kapeikas', 'kapeiku')),
|
|
110
|
+
'SEK': (GENERIC_KRONA, GENERIC_ERA),
|
|
111
|
+
'NOK': (GENERIC_KRONA, GENERIC_ERA),
|
|
112
|
+
'PLN': (('zlots', 'zloti', 'zlotu'),
|
|
113
|
+
('grasis', 'graši', 'grašu')),
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
CURRENCY_ADJECTIVES = {
|
|
117
|
+
'AUD': 'Austrālijas',
|
|
118
|
+
'CAD': 'Kanādas',
|
|
119
|
+
'EEK': 'Igaunijas',
|
|
120
|
+
'USD': 'ASV',
|
|
121
|
+
'RUB': 'Kreivijas',
|
|
122
|
+
'SEK': 'Zviedrijas',
|
|
123
|
+
'NOK': 'Norvēģijas',
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
def setup(self):
|
|
127
|
+
self.negword = "mīnus"
|
|
128
|
+
self.pointword = "komats"
|
|
129
|
+
|
|
130
|
+
def to_cardinal(self, number):
|
|
131
|
+
n = str(number).replace(',', '.')
|
|
132
|
+
base_str, n = self.parse_minus(n)
|
|
133
|
+
if '.' in n:
|
|
134
|
+
left, right = n.split('.')
|
|
135
|
+
leading_zero_count = len(right) - len(right.lstrip('0'))
|
|
136
|
+
decimal_part = ((ZERO[0] + ' ') * leading_zero_count +
|
|
137
|
+
self._int2word(int(right)))
|
|
138
|
+
return '%s%s %s %s' % (
|
|
139
|
+
base_str,
|
|
140
|
+
self._int2word(int(left)),
|
|
141
|
+
self.pointword,
|
|
142
|
+
decimal_part
|
|
143
|
+
)
|
|
144
|
+
else:
|
|
145
|
+
return "%s%s" % (base_str, self._int2word(int(n)))
|
|
146
|
+
|
|
147
|
+
def pluralize(self, n, forms):
|
|
148
|
+
form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2
|
|
149
|
+
return forms[form]
|
|
150
|
+
|
|
151
|
+
def to_currency(self, val, currency='EUR', cents=True, separator=',',
|
|
152
|
+
adjective=False):
|
|
153
|
+
# Handle integers specially - just add currency name without cents
|
|
154
|
+
if isinstance(val, int):
|
|
155
|
+
try:
|
|
156
|
+
cr1, cr2 = self.CURRENCY_FORMS[currency]
|
|
157
|
+
except (KeyError, AttributeError):
|
|
158
|
+
# Fallback to base implementation for unknown currency
|
|
159
|
+
return super(Num2Word_LV, self).to_currency(
|
|
160
|
+
val, currency=currency, cents=cents, separator=separator,
|
|
161
|
+
adjective=adjective)
|
|
162
|
+
|
|
163
|
+
minus_str = self.negword if val < 0 else ""
|
|
164
|
+
abs_val = abs(val)
|
|
165
|
+
money_str = self.to_cardinal(abs_val)
|
|
166
|
+
|
|
167
|
+
# Proper pluralization for currency
|
|
168
|
+
if abs_val == 1:
|
|
169
|
+
currency_str = cr1[0] if isinstance(cr1, tuple) else cr1
|
|
170
|
+
else:
|
|
171
|
+
currency_str = cr1[1] if isinstance(cr1, tuple) and len(cr1) > 1 else (cr1[0] if isinstance(cr1, tuple) else cr1)
|
|
172
|
+
|
|
173
|
+
return (u'%s %s %s' % (minus_str, money_str, currency_str)).strip()
|
|
174
|
+
|
|
175
|
+
# For floats, use the parent class implementation
|
|
176
|
+
return super(Num2Word_LV, self).to_currency(
|
|
177
|
+
val, currency=currency, cents=cents, separator=separator,
|
|
178
|
+
adjective=adjective)
|
|
179
|
+
|
|
180
|
+
def to_ordinal(self, number):
|
|
181
|
+
"""Convert to Latvian ordinal numbers."""
|
|
182
|
+
try:
|
|
183
|
+
num = int(number)
|
|
184
|
+
except (ValueError, TypeError):
|
|
185
|
+
return str(number)
|
|
186
|
+
|
|
187
|
+
# Latvian ordinals
|
|
188
|
+
ordinals = {
|
|
189
|
+
1: 'pirmais',
|
|
190
|
+
2: 'otrais',
|
|
191
|
+
3: 'trešais',
|
|
192
|
+
4: 'ceturtais',
|
|
193
|
+
5: 'piektais',
|
|
194
|
+
6: 'sestais',
|
|
195
|
+
7: 'septītais',
|
|
196
|
+
8: 'astotais',
|
|
197
|
+
9: 'devītais',
|
|
198
|
+
10: 'desmitais',
|
|
199
|
+
11: 'vienpadsmitais',
|
|
200
|
+
12: 'divpadsmitais',
|
|
201
|
+
13: 'trīspadsmitais',
|
|
202
|
+
14: 'četrpadsmitais',
|
|
203
|
+
15: 'piecpadsmitais',
|
|
204
|
+
16: 'sešpadsmitais',
|
|
205
|
+
17: 'septiņpadsmitais',
|
|
206
|
+
18: 'astoņpadsmitais',
|
|
207
|
+
19: 'deviņpadsmitais',
|
|
208
|
+
20: 'divdesmitais',
|
|
209
|
+
30: 'trīsdesmitais',
|
|
210
|
+
40: 'četrdesmitais',
|
|
211
|
+
50: 'piecdesmitais',
|
|
212
|
+
60: 'sešdesmitais',
|
|
213
|
+
70: 'septiņdesmitais',
|
|
214
|
+
80: 'astoņdesmitais',
|
|
215
|
+
90: 'deviņdesmitais',
|
|
216
|
+
100: 'simtais',
|
|
217
|
+
1000: 'tūkstošais',
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if num in ordinals:
|
|
221
|
+
return ordinals[num]
|
|
222
|
+
|
|
223
|
+
# For other numbers, add 'ais' suffix to the cardinal
|
|
224
|
+
# This is a simplified implementation
|
|
225
|
+
cardinal = self.to_cardinal(num)
|
|
226
|
+
# Remove trailing 's' if present and add 'ais'
|
|
227
|
+
if cardinal.endswith('s'):
|
|
228
|
+
return cardinal[:-1] + 'ais'
|
|
229
|
+
return cardinal + 'ais'
|
|
230
|
+
|
|
231
|
+
def _int2word(self, n):
|
|
232
|
+
if n == 0:
|
|
233
|
+
return ZERO[0]
|
|
234
|
+
|
|
235
|
+
words = []
|
|
236
|
+
chunks = list(splitbyx(str(n), 3))
|
|
237
|
+
i = len(chunks)
|
|
238
|
+
for x in chunks:
|
|
239
|
+
i -= 1
|
|
240
|
+
|
|
241
|
+
if x == 0:
|
|
242
|
+
continue
|
|
243
|
+
|
|
244
|
+
n1, n2, n3 = get_digits(x)
|
|
245
|
+
|
|
246
|
+
if n3 > 0:
|
|
247
|
+
if n3 == 1 and n2 == 0 and n1 > 0:
|
|
248
|
+
words.append(HUNDRED[2])
|
|
249
|
+
elif n3 > 1:
|
|
250
|
+
words.append(ONES[n3][0])
|
|
251
|
+
words.append(HUNDRED[1])
|
|
252
|
+
else:
|
|
253
|
+
words.append(HUNDRED[0])
|
|
254
|
+
|
|
255
|
+
if n2 > 1:
|
|
256
|
+
words.append(TWENTIES[n2][0])
|
|
257
|
+
|
|
258
|
+
if n2 == 1:
|
|
259
|
+
words.append(TENS[n1][0])
|
|
260
|
+
elif n1 > 0 and not (i > 0 and x == 1):
|
|
261
|
+
words.append(ONES[n1][0])
|
|
262
|
+
|
|
263
|
+
if i > 0:
|
|
264
|
+
words.append(self.pluralize(x, THOUSANDS[i]))
|
|
265
|
+
|
|
266
|
+
return ' '.join(words)
|
num2words2/lang_MG.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
# Malagasy language support
|
|
24
|
+
class Num2Word_MG(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'MGA': (('ariary', 'ariary'), ('iraimbilanja', 'iraimbilanja')),
|
|
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 = ['', 'iray', 'roa', 'telo', 'efatra', 'dimy', 'enina', 'fito', 'valo', 'sivy']
|
|
35
|
+
self.tens = ['', 'folo', 'roapolo', 'telopolo', 'efapolo', 'dimampolo', 'enimpolo', 'fitopolo', 'valopolo', 'sivifolo']
|
|
36
|
+
self.hundred = "zato"
|
|
37
|
+
self.thousand = "arivo"
|
|
38
|
+
self.million = "tapitrisa"
|
|
39
|
+
|
|
40
|
+
def to_cardinal(self, number):
|
|
41
|
+
"""Convert a number to its word representation in Malagasy."""
|
|
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 Malagasy."""
|
|
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 Malagasy.
|
|
101
|
+
|
|
102
|
+
Malagasy ordinals use 'faha-' prefix for most numbers.
|
|
103
|
+
Special form exists for 1st (voalohany).
|
|
104
|
+
"""
|
|
105
|
+
if number == 1:
|
|
106
|
+
return "voalohany" # first
|
|
107
|
+
else:
|
|
108
|
+
# For other numbers, use "faha-" prefix + cardinal
|
|
109
|
+
cardinal = self.to_cardinal(number)
|
|
110
|
+
return "faha-" + cardinal
|
|
111
|
+
|
|
112
|
+
def to_ordinal_num(self, number):
|
|
113
|
+
"""Convert to abbreviated ordinal."""
|
|
114
|
+
return str(number) + "."
|
|
115
|
+
|
|
116
|
+
def to_year(self, val, longval=True):
|
|
117
|
+
"""Convert to year in Malagasy."""
|
|
118
|
+
return self.to_cardinal(val)
|
|
119
|
+
|
|
120
|
+
def to_currency(self, val, currency='MGA', cents=True, separator=' ', adjective=False):
|
|
121
|
+
"""Convert to currency in Malagasy."""
|
|
122
|
+
is_negative = False
|
|
123
|
+
if val < 0:
|
|
124
|
+
is_negative = True
|
|
125
|
+
val = abs(val)
|
|
126
|
+
|
|
127
|
+
parts = str(val).split('.')
|
|
128
|
+
left = int(parts[0]) if parts[0] else 0
|
|
129
|
+
right = int(parts[1][:2].ljust(2, '0')) if len(parts) > 1 and parts[1] else 0
|
|
130
|
+
|
|
131
|
+
cr1, cr2 = self.CURRENCY_FORMS.get(currency, list(self.CURRENCY_FORMS.values())[0])
|
|
132
|
+
|
|
133
|
+
left_str = self._int_to_word(left)
|
|
134
|
+
result = left_str + " " + (cr1[1] if left != 1 else cr1[0])
|
|
135
|
+
|
|
136
|
+
if cents and right:
|
|
137
|
+
cents_str = self._int_to_word(right)
|
|
138
|
+
result += separator + cents_str + " " + (cr2[1] if right != 1 else cr2[0])
|
|
139
|
+
|
|
140
|
+
if is_negative:
|
|
141
|
+
result = self.negword + result
|
|
142
|
+
|
|
143
|
+
return result.strip()
|