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.
Files changed (133) hide show
  1. num2words2/README.md +69 -0
  2. num2words2/__init__.py +196 -0
  3. num2words2/_version.py +3 -0
  4. num2words2/base.py +377 -0
  5. num2words2/compat.py +29 -0
  6. num2words2/currency.py +60 -0
  7. num2words2/lang_AF.py +202 -0
  8. num2words2/lang_AM.py +193 -0
  9. num2words2/lang_AR.py +435 -0
  10. num2words2/lang_AS.py +119 -0
  11. num2words2/lang_AZ.py +208 -0
  12. num2words2/lang_BA.py +119 -0
  13. num2words2/lang_BE.py +356 -0
  14. num2words2/lang_BG.py +393 -0
  15. num2words2/lang_BN.py +242 -0
  16. num2words2/lang_BO.py +122 -0
  17. num2words2/lang_BR.py +135 -0
  18. num2words2/lang_BS.py +189 -0
  19. num2words2/lang_CA.py +476 -0
  20. num2words2/lang_CE.py +546 -0
  21. num2words2/lang_CS.py +260 -0
  22. num2words2/lang_CY.py +574 -0
  23. num2words2/lang_DA.py +170 -0
  24. num2words2/lang_DE.py +180 -0
  25. num2words2/lang_EL.py +338 -0
  26. num2words2/lang_EN.py +118 -0
  27. num2words2/lang_EN_IN.py +26 -0
  28. num2words2/lang_EN_NG.py +45 -0
  29. num2words2/lang_EO.py +130 -0
  30. num2words2/lang_ES.py +399 -0
  31. num2words2/lang_ES_CO.py +37 -0
  32. num2words2/lang_ES_CR.py +38 -0
  33. num2words2/lang_ES_GT.py +37 -0
  34. num2words2/lang_ES_NI.py +35 -0
  35. num2words2/lang_ES_VE.py +43 -0
  36. num2words2/lang_ET.py +393 -0
  37. num2words2/lang_EU.py +158 -0
  38. num2words2/lang_EUR.py +104 -0
  39. num2words2/lang_FA.py +187 -0
  40. num2words2/lang_FI.py +759 -0
  41. num2words2/lang_FO.py +136 -0
  42. num2words2/lang_FR.py +133 -0
  43. num2words2/lang_FR_BE.py +49 -0
  44. num2words2/lang_FR_CH.py +48 -0
  45. num2words2/lang_FR_DZ.py +35 -0
  46. num2words2/lang_GL.py +135 -0
  47. num2words2/lang_GU.py +172 -0
  48. num2words2/lang_HA.py +293 -0
  49. num2words2/lang_HAW.py +144 -0
  50. num2words2/lang_HE.py +314 -0
  51. num2words2/lang_HI.py +243 -0
  52. num2words2/lang_HR.py +304 -0
  53. num2words2/lang_HT.py +136 -0
  54. num2words2/lang_HU.py +189 -0
  55. num2words2/lang_HY.py +364 -0
  56. num2words2/lang_ID.py +242 -0
  57. num2words2/lang_IS.py +208 -0
  58. num2words2/lang_IT.py +265 -0
  59. num2words2/lang_JA.py +615 -0
  60. num2words2/lang_JW.py +136 -0
  61. num2words2/lang_KA.py +169 -0
  62. num2words2/lang_KK.py +136 -0
  63. num2words2/lang_KM.py +173 -0
  64. num2words2/lang_KN.py +182 -0
  65. num2words2/lang_KO.py +175 -0
  66. num2words2/lang_KZ.py +161 -0
  67. num2words2/lang_LA.py +135 -0
  68. num2words2/lang_LB.py +135 -0
  69. num2words2/lang_LN.py +136 -0
  70. num2words2/lang_LO.py +149 -0
  71. num2words2/lang_LT.py +283 -0
  72. num2words2/lang_LV.py +266 -0
  73. num2words2/lang_MG.py +143 -0
  74. num2words2/lang_MI.py +151 -0
  75. num2words2/lang_MK.py +136 -0
  76. num2words2/lang_ML.py +159 -0
  77. num2words2/lang_MN.py +319 -0
  78. num2words2/lang_MR.py +187 -0
  79. num2words2/lang_MS.py +293 -0
  80. num2words2/lang_MT.py +159 -0
  81. num2words2/lang_MY.py +152 -0
  82. num2words2/lang_NE.py +157 -0
  83. num2words2/lang_NL.py +204 -0
  84. num2words2/lang_NN.py +136 -0
  85. num2words2/lang_NO.py +143 -0
  86. num2words2/lang_OC.py +135 -0
  87. num2words2/lang_PA.py +159 -0
  88. num2words2/lang_PL.py +336 -0
  89. num2words2/lang_PS.py +136 -0
  90. num2words2/lang_PT.py +280 -0
  91. num2words2/lang_PT_BR.py +224 -0
  92. num2words2/lang_RO.py +183 -0
  93. num2words2/lang_RU.py +570 -0
  94. num2words2/lang_SA.py +136 -0
  95. num2words2/lang_SD.py +136 -0
  96. num2words2/lang_SI.py +152 -0
  97. num2words2/lang_SK.py +250 -0
  98. num2words2/lang_SL.py +306 -0
  99. num2words2/lang_SN.py +447 -0
  100. num2words2/lang_SO.py +136 -0
  101. num2words2/lang_SQ.py +252 -0
  102. num2words2/lang_SR.py +254 -0
  103. num2words2/lang_SU.py +136 -0
  104. num2words2/lang_SV.py +169 -0
  105. num2words2/lang_SW.py +219 -0
  106. num2words2/lang_TA.py +303 -0
  107. num2words2/lang_TE.py +169 -0
  108. num2words2/lang_TET.py +285 -0
  109. num2words2/lang_TG.py +149 -0
  110. num2words2/lang_TH.py +214 -0
  111. num2words2/lang_TK.py +136 -0
  112. num2words2/lang_TL.py +145 -0
  113. num2words2/lang_TR.py +882 -0
  114. num2words2/lang_TT.py +136 -0
  115. num2words2/lang_UK.py +1101 -0
  116. num2words2/lang_UR.py +168 -0
  117. num2words2/lang_UZ.py +136 -0
  118. num2words2/lang_VI.py +143 -0
  119. num2words2/lang_WO.py +136 -0
  120. num2words2/lang_YI.py +135 -0
  121. num2words2/lang_YO.py +136 -0
  122. num2words2/lang_ZH.py +296 -0
  123. num2words2/lang_ZH_CN.py +85 -0
  124. num2words2/lang_ZH_HK.py +48 -0
  125. num2words2/lang_ZH_TW.py +198 -0
  126. num2words2/utils.py +35 -0
  127. num2words2-0.1.0.dev1.data/scripts/num2words2 +98 -0
  128. num2words2-0.1.0.dev1.dist-info/METADATA +244 -0
  129. num2words2-0.1.0.dev1.dist-info/RECORD +133 -0
  130. num2words2-0.1.0.dev1.dist-info/WHEEL +5 -0
  131. num2words2-0.1.0.dev1.dist-info/entry_points.txt +2 -0
  132. num2words2-0.1.0.dev1.dist-info/licenses/COPYING +145 -0
  133. num2words2-0.1.0.dev1.dist-info/top_level.txt +1 -0
num2words2/lang_KN.py ADDED
@@ -0,0 +1,182 @@
1
+ # -*- encoding: 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 .lang_EUR import Num2Word_EUR
21
+
22
+
23
+ class Num2Word_KN(Num2Word_EUR):
24
+ def set_high_numwords(self, high):
25
+ for n, word in self.high_numwords:
26
+ self.cards[10**n] = word
27
+
28
+ def setup(self):
29
+ self.low_numwords = [
30
+ "ತೊಂಬತ್ತೊಂಬತ್ತು",
31
+ "ತೊಂಬತ್ತೆಂಟು",
32
+ "ತೊಂಬತ್ತೇಳು",
33
+ "ತೊಂಬತ್ತಾರು",
34
+ "ತೊಂಬತ್ತೈದು",
35
+ "ತೊಂಬತ್ತ ನಾಲ್ಕು",
36
+ "ತೊಂಬತ್ತ ಮೂರು",
37
+ "ತೊಂಬತ್ತೆರಡು",
38
+ "ತೊಂಬತ್ತೊಂದು",
39
+ "ತೊಂಬತ್ತು",
40
+ "ಎಂಬತ್ತೊಂಬತ್ತು",
41
+ "ಎಂಬತ್ತೆಂಟು",
42
+ "ಎಂಬತ್ತೇಳು",
43
+ "ಎಂಬತ್ತಾರು",
44
+ "ಎಂಬತ್ತೈದು",
45
+ "ಎಂಬತ್ತ್ ನಾಲ್ಕು",
46
+ "ಎಂಬತ್ತ್ ಮೂರು",
47
+ "ಎಂಬತ್ತೆರಡು",
48
+ "ಎಂಬತ್ತೊಂದು",
49
+ "ಎಂಬತ್ತು",
50
+ "ಎಪ್ಪತ್ತೊಂಬತ್ತು",
51
+ "ಎಪ್ಪತ್ತೆಂಟು",
52
+ "ಎಪ್ಪತ್ತೇಳು",
53
+ "ಎಪ್ಪತ್ತಾರು",
54
+ "ಎಪ್ಪತ್ತೈದು",
55
+ "ಎಪ್ಪತ್ತ್ ನಾಲ್ಕು",
56
+ "ಎಪ್ಪತ್ತ್ ಮೂರು",
57
+ "ಎಪ್ಪತ್ತೆರಡು",
58
+ "ಎಪ್ಪತ್ತೊಂದು",
59
+ "ಎಪ್ಪತ್ತು",
60
+ "ಅರವತ್ತೊಂಬತ್ತು",
61
+ "ಅರವತ್ತೆಂಟು",
62
+ "ಅರವತ್ತೇಳು",
63
+ "ಅರವತ್ತಾರು",
64
+ "ಅರವತ್ತೈದು",
65
+ "ಅರವತ್ತ್ ನಾಲ್ಕು",
66
+ "ಅರವತ್ತ್ ಮೂರು",
67
+ "ಅರವತ್ತೆರಡು",
68
+ "ಅರವತ್ತೊಂದು",
69
+ "ಅರವತ್ತು",
70
+ "ಐವತ್ತೊಂಬತ್ತು",
71
+ "ಐವತ್ತೆಂಟು",
72
+ "ಐವತ್ತೇಳು",
73
+ "ಐವತ್ತಾರು",
74
+ "ಐವತ್ತೈದು",
75
+ "ಐವತ್ತ್ನಾಲ್ಕು",
76
+ "ಐವತ್ತಮೂರು",
77
+ "ಐವತ್ತೆರಡು",
78
+ "ಐವತ್ತೊಂದು",
79
+ "ಐವತ್ತು",
80
+ "ನಲವತ್ತೊಂಬತ್ತು",
81
+ "ನಲವತ್ತೆಂಟು",
82
+ "ನಲವತ್ತೇಳು",
83
+ "ನಲವತ್ತಾರು",
84
+ "ನಲವತ್ತೈದು",
85
+ "ನಲವತ್ತ್ ನಾಲ್ಕು",
86
+ "ನಲವತ್ತ್ ಮೂರು",
87
+ "ನಲವತ್ತ್ ಎರಡು",
88
+ "ನಲವತ್ತೊಂದು",
89
+ "ನಲವತ್ತು",
90
+ "ಮೂವತ್ತ್ ಒಂಬತ್ತು",
91
+ "ಮೂವತ್ಎಂಟು",
92
+ "ಮೂವತ್ಏಳು",
93
+ "ಮೂವತ್ಆರು",
94
+ "ಮೂವತ್ತ್ ಐದು",
95
+ "ಮೂವತ್ತ್ ನಾಲ್ಕು",
96
+ "ಮೂವತ್ತ್ ಮೂರು",
97
+ "ಮೂವತ್ತ್ಎರಡು",
98
+ "ಮೂವತ್ತ್ಒಂದು",
99
+ "ಮೂವತ್ತು",
100
+ "ಇಪ್ಪತ್ತ್ಒಂಬತ್ತು",
101
+ "ಇಪ್ಪತ್ತ್ಎಂಟು",
102
+ "ಇಪ್ಪತ್ತ್ಏಳು",
103
+ "ಇಪ್ಪತ್ತ್ಆರು",
104
+ "ಇಪ್ಪತ್ತ್ ಐದು",
105
+ "ಇಪ್ಪತ್ತ್ ನಾಲ್ಕು",
106
+ "ಇಪ್ಪತ್ತ್ ಮೂರು",
107
+ "ಇಪ್ಪತ್ತ್ ಎರಡು",
108
+ "ಇಪ್ಪತ್ತ್ ಒಂದು",
109
+ "ಇಪ್ಪತ್ತು",
110
+ "ಹತ್ತೊಂಬತ್ತು",
111
+ "ಹದಿನೆಂಟು",
112
+ "ಹದಿನೇಳು",
113
+ "ಹದಿನಾರು",
114
+ "ಹದಿನೈದು",
115
+ "ಹದಿನಾಲ್ಕು",
116
+ "ಹದಿಮೂರು",
117
+ "ಹನ್ನೆರಡು",
118
+ "ಹನ್ನೊಂದು",
119
+ "ಹತ್ತು",
120
+ "ಒಂಬತ್ತು",
121
+ "ಎಂಟು",
122
+ "ಏಳು",
123
+ "ಆರು",
124
+ "ಐದು",
125
+ "ನಾಲ್ಕು",
126
+ "ಮೂರು",
127
+ "ಎರಡು",
128
+ "ಒಂದು",
129
+ "ಸೊನ್ನೆ",
130
+ ]
131
+
132
+ self.mid_numwords = [(100, "ನೂರು")]
133
+
134
+ self.high_numwords = [(7, "ಕೋಟಿ"), (5, "ಒಂದು ಲಕ್ಷ"), (3, "ಸಾವಿರ")]
135
+
136
+ self.pointword = "ಬಿಂದು"
137
+
138
+ self.modifiers = [
139
+ "್",
140
+ "ಾ",
141
+ "ಿ",
142
+ "ೀ",
143
+ "ೀ",
144
+ "ು",
145
+ "ೂ",
146
+ "ೃ",
147
+ "ೆ",
148
+ "ೇ",
149
+ "ೈ",
150
+ "ೊ",
151
+ "ೋ",
152
+ "ೌ",
153
+ "ೕ",
154
+ ]
155
+
156
+ def merge(self, lpair, rpair):
157
+ ltext, lnum = lpair
158
+ rtext, rnum = rpair
159
+ if lnum == 1 and rnum < 100:
160
+ return (rtext, rnum)
161
+ elif 100 > lnum > rnum:
162
+ return ("%s-%s" % (ltext, rtext), lnum + rnum)
163
+ elif lnum >= 100 > rnum:
164
+ if ltext[-1] in self.modifiers:
165
+ return ("%s %s" % (ltext[:-1], rtext), lnum + rnum)
166
+ else:
167
+ return ("%s %s" % (ltext + "ದ", rtext), lnum + rnum)
168
+ elif rnum > lnum:
169
+ return ("%s %s" % (ltext, rtext), lnum * rnum)
170
+ return ("%s %s" % (ltext, rtext), lnum + rnum)
171
+
172
+ def to_ordinal_num(self, value):
173
+ self.verify_ordinal(value)
174
+ return "%s%s" % (value, self.to_ordinal(value))
175
+
176
+ def to_ordinal(self, value):
177
+ self.verify_ordinal(value)
178
+ outwords = self.to_cardinal(value)
179
+ if outwords[-1] in self.modifiers:
180
+ outwords = outwords[:-1]
181
+ ordinal_num = outwords + "ನೇ"
182
+ return ordinal_num
num2words2/lang_KO.py ADDED
@@ -0,0 +1,175 @@
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 division, print_function, unicode_literals
19
+
20
+ from .base import Num2Word_Base
21
+ from .currency import parse_currency_parts
22
+
23
+
24
+ class Num2Word_KO(Num2Word_Base):
25
+ CURRENCY_FORMS = {
26
+ 'KRW': ('원',), # KRW doesn't use fractional units
27
+ 'USD': ('달러', '센트'),
28
+ 'JPY': ('엔',) # JPY doesn't use fractional units
29
+ }
30
+
31
+ def set_high_numwords(self, high):
32
+ max = 4 * len(high)
33
+ for word, n in zip(high, range(max, 0, -4)):
34
+ self.cards[10 ** n] = word
35
+
36
+ def setup(self):
37
+ super(Num2Word_KO, self).setup()
38
+
39
+ self.negword = "마이너스 "
40
+ self.pointword = "점"
41
+
42
+ self.high_numwords = [
43
+ '무량대수',
44
+ '불가사의',
45
+ '나유타',
46
+ '아승기',
47
+ '항하사',
48
+ '극',
49
+ '재',
50
+ '정',
51
+ '간',
52
+ '구',
53
+ '양',
54
+ '자',
55
+ '해',
56
+ '경',
57
+ '조',
58
+ '억',
59
+ '만']
60
+ self.mid_numwords = [(1000, "천"), (100, "백")]
61
+ self.low_numwords = ["십", "구", "팔", "칠", "육", "오", "사", "삼", "이",
62
+ "일", "영"]
63
+ self.ords = {"일": "한",
64
+ "이": "두",
65
+ "삼": "세",
66
+ "사": "네",
67
+ "오": "다섯",
68
+ "육": "여섯",
69
+ "칠": "일곱",
70
+ "팔": "여덟",
71
+ "구": "아홉",
72
+ "십": "열",
73
+ "이십": "스물",
74
+ "삼십": "서른",
75
+ "사십": "마흔",
76
+ "오십": "쉰",
77
+ "육십": "예순",
78
+ "칠십": "일흔",
79
+ "팔십": "여든",
80
+ "구십": "아흔"}
81
+
82
+ def merge(self, lpair, rpair):
83
+ ltext, lnum = lpair
84
+ rtext, rnum = rpair
85
+ if lnum == 1 and rnum <= 10000:
86
+ return rpair
87
+ elif 10000 > lnum > rnum:
88
+ return ("%s%s" % (ltext, rtext), lnum + rnum)
89
+ elif lnum >= 10000 and lnum > rnum:
90
+ return ("%s %s" % (ltext, rtext), lnum + rnum)
91
+ else:
92
+ return ("%s%s" % (ltext, rtext), lnum * rnum)
93
+
94
+ def to_ordinal(self, value):
95
+ self.verify_ordinal(value)
96
+ if value == 1:
97
+ return "첫 번째"
98
+ outwords = self.to_cardinal(value).split(" ")
99
+ lastwords = outwords[-1].split("백")
100
+ if "십" in lastwords[-1]:
101
+ ten_one = lastwords[-1].split("십")
102
+ ten_one[0] = self.ords[ten_one[0] + "십"]
103
+ try:
104
+ ten_one[1] = self.ords[ten_one[1]]
105
+ ten_one[0] = ten_one[0].replace("스무", "스물")
106
+ except KeyError:
107
+ pass
108
+ lastwords[-1] = ''.join(ten_one)
109
+ else:
110
+ lastwords[-1] = self.ords[lastwords[-1]]
111
+ outwords[-1] = "백 ".join(lastwords)
112
+ return " ".join(outwords) + " 번째"
113
+
114
+ def to_ordinal_num(self, value):
115
+ self.verify_ordinal(value)
116
+ return "%s 번째" % (value)
117
+
118
+ def to_currency(self, val, currency='KRW', cents=True, separator=' ',
119
+ adjective=False):
120
+ """Convert a number to currency words."""
121
+ # Track if input was originally an integer
122
+ is_integer_input = isinstance(val, int)
123
+
124
+ # Check if value has fractional cents
125
+ from decimal import Decimal
126
+ decimal_val = Decimal(str(val))
127
+ has_fractional_cents = (decimal_val * 100) % 1 != 0
128
+
129
+ left, right, is_negative = parse_currency_parts(val, is_int_with_cents=False,
130
+ keep_precision=has_fractional_cents)
131
+
132
+ try:
133
+ curr_forms = self.CURRENCY_FORMS[currency]
134
+ major = curr_forms[0]
135
+ minor = curr_forms[1] if len(curr_forms) > 1 else None
136
+ except KeyError:
137
+ raise NotImplementedError(
138
+ 'Currency "%s" not implemented for "%s"' % (
139
+ currency, self.__class__.__name__))
140
+
141
+ minus_str = self.negword if is_negative else ""
142
+ money_str = self.to_cardinal(left)
143
+
144
+ # For currencies without minor units
145
+ if minor is None:
146
+ # Raise error if decimals provided for currency without minor unit
147
+ if not is_integer_input and right > 0:
148
+ raise ValueError("Currency '%s' does not support decimals" % currency)
149
+ return "%s%s%s" % (minus_str, money_str, major)
150
+
151
+ # For currencies with minor units
152
+ # For integers, don't show cents
153
+ if is_integer_input:
154
+ return "%s%s%s" % (minus_str, money_str, major)
155
+
156
+ # For floats, handle fractional cents
157
+ if isinstance(right, Decimal) and has_fractional_cents:
158
+ # Convert fractional cents (e.g., 65.3 cents)
159
+ cents_str = self.to_cardinal_float(float(right))
160
+ elif cents:
161
+ cents_str = self.to_cardinal(int(right)) if right > 0 else self.to_cardinal(0)
162
+ else:
163
+ cents_str = str(int(right))
164
+
165
+ return "%s%s%s%s%s%s" % (
166
+ minus_str, money_str, major,
167
+ separator, cents_str, minor)
168
+
169
+ def to_year(self, val, suffix=None, longval=True):
170
+ if val < 0:
171
+ val = abs(val)
172
+ suffix = '기원전' if not suffix else suffix
173
+ valtext = self.to_cardinal(val)
174
+ return (valtext if not suffix
175
+ else "%s %s" % (suffix, valtext))
num2words2/lang_KZ.py ADDED
@@ -0,0 +1,161 @@
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 = 'нөл'
24
+
25
+ ONES = {
26
+ 1: 'бір',
27
+ 2: 'екі',
28
+ 3: 'үш',
29
+ 4: 'төрт',
30
+ 5: 'бес',
31
+ 6: 'алты',
32
+ 7: 'жеті',
33
+ 8: 'сегіз',
34
+ 9: 'тоғыз',
35
+ }
36
+
37
+ TEN = 'он'
38
+
39
+ TWENTIES = {
40
+ 2: 'жиырма',
41
+ 3: 'отыз',
42
+ 4: 'қырық',
43
+ 5: 'елу',
44
+ 6: 'алпыс',
45
+ 7: 'жетпіс',
46
+ 8: 'сексен',
47
+ 9: 'тоқсан',
48
+ }
49
+
50
+ HUNDRED = 'жүз'
51
+
52
+ THOUSANDS = {
53
+ 1: 'мың',
54
+ 2: 'миллион',
55
+ 3: 'миллиард',
56
+ 4: 'триллион',
57
+ 5: 'квадриллион',
58
+ 6: 'квинтиллион',
59
+ 7: 'секстиллион',
60
+ 8: 'септиллион',
61
+ 9: 'октиллион',
62
+ 10: 'нониллион',
63
+ }
64
+
65
+
66
+ class Num2Word_KZ(Num2Word_Base):
67
+ CURRENCY_FORMS = {
68
+ 'USD': ('доллар', 'цент'),
69
+ 'KZT': ('теңге', 'тиын'),
70
+ }
71
+
72
+ def setup(self):
73
+ self.negword = "минус"
74
+ self.pointword = "бүтін"
75
+
76
+ def to_cardinal(self, number):
77
+ n = str(number).replace(',', '.')
78
+ if '.' in n:
79
+ is_negative = n.startswith('-')
80
+ abs_n = n[1:] if is_negative else n
81
+ left, right = abs_n.split('.')
82
+ leading_zero_count = len(right) - len(right.lstrip('0'))
83
+ result = u'%s %s %s' % (
84
+ self._int2word(int(left)),
85
+ self.pointword,
86
+ (ZERO + ' ') * leading_zero_count + self._int2word(int(right))
87
+ )
88
+ if is_negative:
89
+ result = self.negword + ' ' + result
90
+ return result
91
+ else:
92
+ return self._int2word(int(n))
93
+
94
+ def pluralize(self, n, form):
95
+ return form
96
+
97
+ def to_ordinal(self, number):
98
+ """Convert to ordinal in Kazakh"""
99
+ if number == 0:
100
+ return ZERO + 'інші'
101
+
102
+ # Get the cardinal form
103
+ cardinal = self.to_cardinal(number)
104
+
105
+ # In Kazakh, ordinals are formed by adding suffixes
106
+ # The suffix depends on the last sound of the number
107
+ # Common suffixes: -ыншы/-інші, -ншы/-нші
108
+
109
+ # Check last character to determine suffix
110
+ if cardinal[-1] in 'аоұыеэ':
111
+ return cardinal + 'ншы'
112
+ elif cardinal[-1] in 'әіүө':
113
+ return cardinal + 'нші'
114
+ elif cardinal[-1] in 'бвгғджзйклмнңпрстфхһцчшщ':
115
+ # After consonants
116
+ if any(v in cardinal[-2:] for v in 'аоұы'):
117
+ return cardinal + 'ыншы'
118
+ else:
119
+ return cardinal + 'інші'
120
+ else:
121
+ # Default case
122
+ return cardinal + 'інші'
123
+
124
+ def _cents_verbose(self, number, currency):
125
+ return self._int2word(number, currency == 'KZT')
126
+
127
+ def _int2word(self, n, feminine=False):
128
+ if n < 0:
129
+ return ' '.join([self.negword, self._int2word(abs(n))])
130
+
131
+ if n == 0:
132
+ return ZERO
133
+
134
+ words = []
135
+ chunks = list(splitbyx(str(n), 3))
136
+ i = len(chunks)
137
+ for x in chunks:
138
+ i -= 1
139
+
140
+ if x == 0:
141
+ continue
142
+
143
+ n1, n2, n3 = get_digits(x)
144
+
145
+ if n3 > 0:
146
+ if n3 > 1:
147
+ words.append(ONES[n3])
148
+ words.append(HUNDRED)
149
+
150
+ if n2 == 1:
151
+ words.append(TEN)
152
+ elif n2 > 1:
153
+ words.append(TWENTIES[n2])
154
+
155
+ if n1 > 0:
156
+ words.append(ONES[n1])
157
+
158
+ if i > 0:
159
+ words.append(THOUSANDS[i])
160
+
161
+ return ' '.join(words)
num2words2/lang_LA.py ADDED
@@ -0,0 +1,135 @@
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
+ # Latin language support
24
+ class Num2Word_LA(Num2Word_Base):
25
+ CURRENCY_FORMS = {
26
+ 'EUR': (('euro', 'euros'), ('centesima', 'centesimae')),
27
+ 'USD': (('dollar', 'dollars'), ('cent', 'cents'))
28
+ }
29
+
30
+ def setup(self):
31
+ self.negword = "minus "
32
+ self.pointword = "point"
33
+ self.ones = ['', 'unus', 'duo', 'tres', 'quattuor', 'quinque', 'sex', 'septem', 'octo', 'novem']
34
+ self.tens = ['', 'decem', 'viginti', 'triginta', 'quadraginta', 'quinquaginta', 'sexaginta', 'septuaginta', 'octoginta', 'nonaginta']
35
+ self.hundred = "centum"
36
+ self.thousand = "mille"
37
+ self.million = "decies centena milia"
38
+
39
+ def to_cardinal(self, number):
40
+ """Convert a number to its word representation in Latin."""
41
+ n = str(number).strip()
42
+
43
+ if n.startswith('-'):
44
+ n = n[1:]
45
+ ret = self.negword
46
+ else:
47
+ ret = ""
48
+
49
+ if '.' in n:
50
+ left, right = n.split('.', 1)
51
+ ret += self._int_to_word(int(left)) + " " + self.pointword + " "
52
+ for digit in right:
53
+ ret += self._int_to_word(int(digit)) + " "
54
+ return ret.strip()
55
+ else:
56
+ return (ret + self._int_to_word(int(n))).strip()
57
+
58
+ def _int_to_word(self, number):
59
+ """Convert an integer to its word representation in Latin."""
60
+ if number == 0:
61
+ return self.ones[0] if self.ones[0] else "zero"
62
+
63
+ if number < 0:
64
+ return self.negword + self._int_to_word(abs(number))
65
+ elif number < 10:
66
+ return self.ones[number]
67
+ elif number < 100:
68
+ tens_val = number // 10
69
+ ones_val = number % 10
70
+ if ones_val == 0:
71
+ return self.tens[tens_val]
72
+ else:
73
+ return self.tens[tens_val] + " " + self.ones[ones_val]
74
+ elif number < 1000:
75
+ hundreds_val = number // 100
76
+ remainder = number % 100
77
+ result = self.ones[hundreds_val] + " " + self.hundred
78
+ if remainder:
79
+ result += " " + self._int_to_word(remainder)
80
+ return result
81
+ elif number < 1000000:
82
+ thousands_val = number // 1000
83
+ remainder = number % 1000
84
+ result = self._int_to_word(thousands_val) + " " + self.thousand
85
+ if remainder:
86
+ result += " " + self._int_to_word(remainder)
87
+ return result
88
+ elif number < 1000000000:
89
+ millions_val = number // 1000000
90
+ remainder = number % 1000000
91
+ result = self._int_to_word(millions_val) + " " + self.million
92
+ if remainder:
93
+ result += " " + self._int_to_word(remainder)
94
+ return result
95
+ else:
96
+ return str(number) # Fallback for very large numbers
97
+
98
+ def to_ordinal(self, number):
99
+ """Convert to ordinal in Latin."""
100
+ cardinal = self.to_cardinal(number)
101
+ # Language-specific ordinal suffix
102
+ return cardinal + "-us"
103
+
104
+ def to_ordinal_num(self, number):
105
+ """Convert to abbreviated ordinal."""
106
+ return str(number) + "."
107
+
108
+ def to_year(self, val, longval=True):
109
+ """Convert to year in Latin."""
110
+ return self.to_cardinal(val)
111
+
112
+ def to_currency(self, val, currency='EUR', cents=True, separator=' ', adjective=False):
113
+ """Convert to currency in Latin."""
114
+ is_negative = False
115
+ if val < 0:
116
+ is_negative = True
117
+ val = abs(val)
118
+
119
+ parts = str(val).split('.')
120
+ left = int(parts[0]) if parts[0] else 0
121
+ right = int(parts[1][:2].ljust(2, '0')) if len(parts) > 1 and parts[1] else 0
122
+
123
+ cr1, cr2 = self.CURRENCY_FORMS.get(currency, list(self.CURRENCY_FORMS.values())[0])
124
+
125
+ left_str = self._int_to_word(left)
126
+ result = left_str + " " + (cr1[1] if left != 1 else cr1[0])
127
+
128
+ if cents and right:
129
+ cents_str = self._int_to_word(right)
130
+ result += separator + cents_str + " " + (cr2[1] if right != 1 else cr2[0])
131
+
132
+ if is_negative:
133
+ result = self.negword + result
134
+
135
+ return result.strip()