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_DA.py ADDED
@@ -0,0 +1,170 @@
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 . import lang_EUR
21
+
22
+
23
+ class Num2Word_DA(lang_EUR.Num2Word_EUR):
24
+ GIGA_SUFFIX = "illiarder"
25
+ MEGA_SUFFIX = "illioner"
26
+
27
+ CURRENCY_FORMS = {
28
+ 'DKK': (('krone', 'kroner'), ('øre', 'øre')),
29
+ 'EUR': (('euro', 'euro'), ('cent', 'cent')),
30
+ 'USD': (('dollar', 'dollars'), ('cent', 'cent')),
31
+ 'GBP': (('pund', 'pund'), ('penny', 'pence')),
32
+ 'SEK': (('krone', 'kroner'), ('øre', 'øre')),
33
+ 'NOK': (('krone', 'kroner'), ('øre', 'øre')),
34
+ }
35
+
36
+ def setup(self):
37
+ super(Num2Word_DA, self).setup()
38
+
39
+ self.negword = "minus "
40
+ self.pointword = "komma"
41
+ self.exclude_title = ["og", "komma", "minus"]
42
+
43
+ self.mid_numwords = [(1000, "tusind"), (100, "hundrede"),
44
+ (90, "halvfems"), (80, "firs"),
45
+ (70, "halvfjerds"), (60, "treds"),
46
+ (50, "halvtreds"), (40, "fyrre"), (30, "tredive")]
47
+ self.low_numwords = ["tyve", "nitten", "atten", "sytten",
48
+ "seksten", "femten", "fjorten", "tretten",
49
+ "tolv", "elleve", "ti", "ni", "otte",
50
+ "syv", "seks", "fem", "fire", "tre", "to",
51
+ "et", "nul"]
52
+ self.ords = {"nul": "nul",
53
+ "et": "f\xf8rste",
54
+ "to": "anden",
55
+ "tre": "tredje",
56
+ "fire": "fjerde",
57
+ "fem": "femte",
58
+ "seks": "sjette",
59
+ "syv": "syvende",
60
+ "otte": "ottende",
61
+ "ni": "niende",
62
+ "ti": "tiende",
63
+ "elleve": "ellevte",
64
+ "tolv": "tolvte",
65
+ "tretten": "trett",
66
+ "fjorten": "fjort",
67
+ "femten": "femt",
68
+ "seksten": "sekst",
69
+ "sytten": "sytt",
70
+ "atten": "att",
71
+ "nitten": "nitt",
72
+ "tyve": "tyv"}
73
+ self.ordflag = False
74
+
75
+ def merge(self, curr, next):
76
+ ctext, cnum, ntext, nnum = curr + next
77
+ if next[1] == 100 or next[1] == 1000:
78
+ lst = list(next)
79
+ # Special handling: don't concat "et" directly for 10000
80
+ if cnum == 10 and nnum == 1000:
81
+ # 10 * 1000 = "ti tusind" with space
82
+ return ("ti tusind", 10000)
83
+ elif cnum == 100 and nnum == 1000:
84
+ # 100 * 1000 = "ethundrede tusind" with space
85
+ return ("ethundrede tusind", 100000)
86
+ lst[0] = 'et' + lst[0]
87
+ next = tuple(lst)
88
+
89
+ if cnum == 1:
90
+ if nnum < 10 ** 6 or self.ordflag:
91
+ return next
92
+ ctext = "en"
93
+ if nnum > cnum:
94
+ if nnum >= 10 ** 6:
95
+ ctext += " "
96
+ val = cnum * nnum
97
+ else:
98
+ if cnum >= 100 and cnum < 1000:
99
+ ctext += " og "
100
+ elif cnum >= 1000 and cnum <= 100000:
101
+ ctext += "e og "
102
+ if nnum < 10 < cnum < 100:
103
+ if nnum == 1:
104
+ ntext = "en"
105
+ ntext, ctext = ctext, ntext + "og"
106
+ elif cnum >= 10 ** 6:
107
+ ctext += " "
108
+ val = cnum + nnum
109
+ word = ctext + ntext
110
+ return (word, val)
111
+
112
+ def to_ordinal(self, value):
113
+ self.verify_ordinal(value)
114
+ self.ordflag = True
115
+ outword = self.to_cardinal(value)
116
+ self.ordflag = False
117
+ for key in self.ords:
118
+ if outword.endswith(key):
119
+ outword = outword[:len(outword) - len(key)] + self.ords[key]
120
+ break
121
+ if value % 100 >= 30 and value % 100 <= 39 or value % 100 == 0:
122
+ outword += "te"
123
+ elif value % 100 > 12 or value % 100 == 0:
124
+ outword += "ende"
125
+ return outword
126
+
127
+ def to_ordinal_num(self, value):
128
+ self.verify_ordinal(value)
129
+ vaerdte = (0, 1, 5, 6, 11, 12)
130
+ if value % 100 >= 30 and value % 100 <= 39 or value % 100 in vaerdte:
131
+ return str(value) + "te"
132
+ elif value % 100 == 2:
133
+ return str(value) + "en"
134
+ return str(value) + "ende"
135
+
136
+ def to_currency(self, val, currency='DKK', cents=True, separator=',',
137
+ adjective=False, longval=True):
138
+ # Handle integers specially - just add currency name without cents
139
+ if isinstance(val, int):
140
+ try:
141
+ cr1, cr2 = self.CURRENCY_FORMS[currency]
142
+ except (KeyError, AttributeError):
143
+ # Fallback to base implementation for unknown currency
144
+ return super(Num2Word_DA, self).to_currency(
145
+ val, currency=currency, cents=cents, separator=separator,
146
+ adjective=adjective)
147
+
148
+ minus_str = self.negword if val < 0 else ""
149
+ abs_val = abs(val)
150
+ money_str = self.to_cardinal(abs_val)
151
+
152
+ # Proper pluralization for currency
153
+ if abs_val == 1:
154
+ currency_str = cr1[0] if isinstance(cr1, tuple) else cr1
155
+ else:
156
+ currency_str = cr1[1] if isinstance(cr1, tuple) and len(cr1) > 1 else (cr1[0] if isinstance(cr1, tuple) else cr1)
157
+
158
+ return (u'%s %s %s' % (minus_str, money_str, currency_str)).strip()
159
+
160
+ # For floats, use the parent class implementation
161
+ return super(Num2Word_DA, self).to_currency(
162
+ val, currency=currency, cents=cents, separator=separator,
163
+ adjective=adjective)
164
+
165
+ def to_year(self, val, longval=True):
166
+ if val == 1:
167
+ return 'en'
168
+ if not (val // 100) % 10:
169
+ return self.to_cardinal(val)
170
+ return self.to_splitnum(val, hightxt="hundrede", longval=longval)
num2words2/lang_DE.py ADDED
@@ -0,0 +1,180 @@
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 print_function, unicode_literals
19
+
20
+ import re
21
+
22
+ from .lang_EUR import Num2Word_EUR
23
+
24
+
25
+ class Num2Word_DE(Num2Word_EUR):
26
+ CURRENCY_FORMS = {
27
+ 'EUR': (('Euro', 'Euro'), ('Cent', 'Cent')),
28
+ 'GBP': (('Pfund', 'Pfund'), ('Penny', 'Pence')),
29
+ 'USD': (('Dollar', 'Dollar'), ('Cent', 'Cent')),
30
+ 'CNY': (('Yuan', 'Yuan'), ('Jiao', 'Fen')),
31
+ 'DEM': (('Mark', 'Mark'), ('Pfennig', 'Pfennig')),
32
+ 'CHF': (('Schweizer Franken', 'Schweizer Franken'), ('Rappen', 'Rappen')),
33
+ 'JPY': (('Yen', 'Yen'), ('Sen', 'Sen')),
34
+ }
35
+
36
+ GIGA_SUFFIX = "illiarde"
37
+ MEGA_SUFFIX = "illion"
38
+
39
+ def setup(self):
40
+ self.negword = "minus "
41
+ self.pointword = "Komma"
42
+ # "Cannot treat float %s as ordinal."
43
+ self.errmsg_floatord = (
44
+ "Die Gleitkommazahl %s kann nicht in eine Ordnungszahl " +
45
+ "konvertiert werden."
46
+ )
47
+ # "type(((type(%s)) ) not in [long, int, float]"
48
+ self.errmsg_nonnum = (
49
+ "Nur Zahlen (type(%s)) können in Wörter konvertiert werden."
50
+ )
51
+ # "Cannot treat negative num %s as ordinal."
52
+ self.errmsg_negord = (
53
+ "Die negative Zahl %s kann nicht in eine Ordnungszahl " +
54
+ "konvertiert werden."
55
+ )
56
+ # "abs(%s) must be less than %s."
57
+ self.errmsg_toobig = "Die Zahl %s muss kleiner als %s sein."
58
+ self.exclude_title = []
59
+
60
+ lows = ["Non", "Okt", "Sept", "Sext", "Quint", "Quadr", "Tr", "B", "M"]
61
+ units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept",
62
+ "okto", "novem"]
63
+ tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint",
64
+ "sexagint", "septuagint", "oktogint", "nonagint"]
65
+ self.high_numwords = (
66
+ ["zent"] + self.gen_high_numwords(units, tens, lows)
67
+ )
68
+ self.mid_numwords = [(1000, "tausend"), (100, "hundert"),
69
+ (90, "neunzig"), (80, "achtzig"), (70, "siebzig"),
70
+ (60, "sechzig"), (50, "f\xFCnfzig"),
71
+ (40, "vierzig"), (30, "drei\xDFig")]
72
+ self.low_numwords = ["zwanzig", "neunzehn", "achtzehn", "siebzehn",
73
+ "sechzehn", "f\xFCnfzehn", "vierzehn", "dreizehn",
74
+ "zw\xF6lf", "elf", "zehn", "neun", "acht",
75
+ "sieben", "sechs", "f\xFCnf", "vier", "drei",
76
+ "zwei", "eins", "null"]
77
+ self.ords = {"eins": "ers",
78
+ "drei": "drit",
79
+ "acht": "ach",
80
+ "sieben": "sieb",
81
+ "ig": "igs",
82
+ "ert": "erts",
83
+ "end": "ends",
84
+ "ion": "ions",
85
+ "nen": "ns",
86
+ "rde": "rds",
87
+ "rden": "rds"}
88
+
89
+ def merge(self, curr, next):
90
+ ctext, cnum, ntext, nnum = curr + next
91
+
92
+ if cnum == 1:
93
+ if nnum == 100 or nnum == 1000:
94
+ return ("ein" + ntext, nnum)
95
+ elif nnum < 10 ** 6:
96
+ return next
97
+ ctext = "eine"
98
+
99
+ if nnum > cnum:
100
+ if nnum >= 10 ** 6:
101
+ if cnum > 1:
102
+ if ntext.endswith("e"):
103
+ ntext += "n"
104
+ else:
105
+ ntext += "en"
106
+ ctext += " "
107
+ val = cnum * nnum
108
+ else:
109
+ if nnum < 10 < cnum < 100:
110
+ if nnum == 1:
111
+ ntext = "ein"
112
+ ntext, ctext = ctext, ntext + "und"
113
+ elif cnum >= 10 ** 6:
114
+ ctext += " "
115
+ val = cnum + nnum
116
+
117
+ word = ctext + ntext
118
+ return (word, val)
119
+
120
+ def to_ordinal(self, value):
121
+ self.verify_ordinal(value)
122
+ outword = self.to_cardinal(value).lower()
123
+ for key in self.ords:
124
+ if outword.endswith(key):
125
+ outword = outword[:len(outword) - len(key)] + self.ords[key]
126
+ break
127
+
128
+ res = outword + "te"
129
+
130
+ # Exception: "hundertste" is usually preferred over "einhundertste"
131
+ if res == "eintausendste" or res == "einhundertste":
132
+ res = res.replace("ein", "", 1)
133
+ # ... similarly for "millionste" etc.
134
+ res = re.sub(r'eine ([a-z]+(illion|illiard)ste)$',
135
+ lambda m: m.group(1), res)
136
+ # Ordinals involving "Million" etc. are written without a space.
137
+ # see https://de.wikipedia.org/wiki/Million#Sprachliches
138
+ res = re.sub(r' ([a-z]+(illion|illiard)ste)$',
139
+ lambda m: m.group(1), res)
140
+
141
+ return res
142
+
143
+ def to_ordinal_num(self, value):
144
+ self.verify_ordinal(value)
145
+ return str(value) + "."
146
+
147
+ def to_currency(self, val, currency='EUR', cents=True, separator=' und',
148
+ adjective=False):
149
+ # Handle integers specially - just add currency name without cents
150
+ if isinstance(val, int):
151
+ try:
152
+ cr1, cr2 = self.CURRENCY_FORMS[currency]
153
+ except (KeyError, AttributeError):
154
+ # Fallback to base implementation for unknown currency
155
+ return super(Num2Word_DE, self).to_currency(
156
+ val, currency=currency, cents=cents, separator=separator,
157
+ adjective=adjective)
158
+
159
+ minus_str = self.negword if val < 0 else ""
160
+ abs_val = abs(val)
161
+ money_str = self.to_cardinal(abs_val)
162
+
163
+ # Proper pluralization for currency
164
+ if abs_val == 1:
165
+ currency_str = cr1[0] if isinstance(cr1, tuple) else cr1
166
+ else:
167
+ currency_str = cr1[1] if isinstance(cr1, tuple) and len(cr1) > 1 else (cr1[0] if isinstance(cr1, tuple) else cr1)
168
+
169
+ return (u'%s %s %s' % (minus_str, money_str, currency_str)).strip()
170
+
171
+ # For floats, use the parent class implementation
172
+ return super(Num2Word_DE, self).to_currency(
173
+ val, currency=currency, cents=cents, separator=separator,
174
+ adjective=adjective)
175
+
176
+ def to_year(self, val, longval=True):
177
+ if not (val // 100) % 10:
178
+ return self.to_cardinal(val)
179
+ return self.to_splitnum(val, hightxt="hundert", longval=longval)\
180
+ .replace(' ', '')