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_YI.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
|
+
# Yiddish language support
|
|
24
|
+
class Num2Word_YI(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'EUR': (('אייראָ', 'אייראָ'), ('צענט', 'צענט')),
|
|
27
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents'))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def setup(self):
|
|
31
|
+
self.negword = "minus "
|
|
32
|
+
self.pointword = "point"
|
|
33
|
+
self.ones = ['', 'איינס', 'צוויי', 'דרײַ', 'פיר', 'פינף', 'זעקס', 'זיבן', 'אַכט', 'נײַן']
|
|
34
|
+
self.tens = ['', 'צען', 'צוואַנציק', 'דרײַסיק', 'פערציק', 'פופציק', 'זעכציק', 'זיבעציק', 'אַכציק', 'נײַנציק']
|
|
35
|
+
self.hundred = "הונדערט"
|
|
36
|
+
self.thousand = "טויזנט"
|
|
37
|
+
self.million = "מיליאָן"
|
|
38
|
+
|
|
39
|
+
def to_cardinal(self, number):
|
|
40
|
+
"""Convert a number to its word representation in Yiddish."""
|
|
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 Yiddish."""
|
|
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 Yiddish."""
|
|
100
|
+
cardinal = self.to_cardinal(number)
|
|
101
|
+
# Language-specific ordinal suffix
|
|
102
|
+
return cardinal + "-טער"
|
|
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 Yiddish."""
|
|
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 Yiddish."""
|
|
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()
|
num2words2/lang_YO.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
|
+
# Yoruba language support
|
|
24
|
+
class Num2Word_YO(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'NGN': (('náírà', 'náírà'), ('kóbò', 'kóbò')),
|
|
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 = ['', 'ọkan', 'méjì', 'mẹta', 'mẹrin', 'marun', 'mẹfa', 'meje', 'mẹjọ', 'mẹsan']
|
|
35
|
+
self.tens = ['', 'mẹwa', 'ogún', 'ọgbọn', 'ogójì', 'àádọta', 'ọgọta', 'àádọrin', 'ọgọrin', 'àádọrún']
|
|
36
|
+
self.hundred = "ọgọrun"
|
|
37
|
+
self.thousand = "ẹgbẹrun"
|
|
38
|
+
self.million = "miliọnu"
|
|
39
|
+
|
|
40
|
+
def to_cardinal(self, number):
|
|
41
|
+
"""Convert a number to its word representation in Yoruba."""
|
|
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 Yoruba."""
|
|
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 Yoruba."""
|
|
101
|
+
cardinal = self.to_cardinal(number)
|
|
102
|
+
# Language-specific ordinal suffix
|
|
103
|
+
return cardinal + "-kẹta"
|
|
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 Yoruba."""
|
|
111
|
+
return self.to_cardinal(val)
|
|
112
|
+
|
|
113
|
+
def to_currency(self, val, currency='NGN', cents=True, separator=' ', adjective=False):
|
|
114
|
+
"""Convert to currency in Yoruba."""
|
|
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_ZH.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
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 .compat import strtype
|
|
22
|
+
from .currency import parse_currency_parts
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Num2Word_ZH(Num2Word_Base):
|
|
26
|
+
CURRENCY_FLOATS = ["角", "分"]
|
|
27
|
+
|
|
28
|
+
CURRENCY_FORMS = {
|
|
29
|
+
"XXX": "元", # Generic dollar
|
|
30
|
+
"CNY": "人民幣",
|
|
31
|
+
"NTD": "新台幣",
|
|
32
|
+
"HKD": "港幣",
|
|
33
|
+
"MOP": "澳門幣",
|
|
34
|
+
"SGD": "新加坡元",
|
|
35
|
+
"MYR": "馬來西亞令吉",
|
|
36
|
+
"USD": "美元",
|
|
37
|
+
"EUR": "歐元",
|
|
38
|
+
"GBP": "英鎊",
|
|
39
|
+
"JPY": "日元",
|
|
40
|
+
"CHF": "瑞士法郎",
|
|
41
|
+
"CAD": "加元",
|
|
42
|
+
"AUD": "澳幣",
|
|
43
|
+
"NZD": "紐西蘭元",
|
|
44
|
+
"THB": "泰銖",
|
|
45
|
+
"KRW": "韓元",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
cheque_suffix = "正"
|
|
49
|
+
year = "年"
|
|
50
|
+
year_prefix = ("公元", "西元")
|
|
51
|
+
year_bce = "前"
|
|
52
|
+
ord_prefix = "第"
|
|
53
|
+
|
|
54
|
+
def set_high_numwords(self, high):
|
|
55
|
+
max = 4 * len(high)
|
|
56
|
+
for word, n in zip(high, range(max, 0, -4)):
|
|
57
|
+
self.cards[10 ** n] = word
|
|
58
|
+
|
|
59
|
+
def to_cardinal(self, value, stuff_zero=2, reading=False, prefer=None):
|
|
60
|
+
self.stuff_zero = stuff_zero
|
|
61
|
+
self.set_str_selection(reading, prefer)
|
|
62
|
+
|
|
63
|
+
out = super().to_cardinal(value).replace(" ", "")
|
|
64
|
+
return self.zh_to_cap(out, reading == "capital")
|
|
65
|
+
|
|
66
|
+
def to_cardinal_float(self, value):
|
|
67
|
+
out = super().to_cardinal_float(value).replace(" ", "")
|
|
68
|
+
return self.zh_to_cap(out, self.capital)
|
|
69
|
+
|
|
70
|
+
def merge(self, lpair, rpair):
|
|
71
|
+
ltext, lnum = lpair
|
|
72
|
+
rtext, rnum = rpair
|
|
73
|
+
ltext, rtext = self.select_text(ltext), self.select_text(rtext)
|
|
74
|
+
# ignore lpair if lnum is 1 and rnum is less than 10
|
|
75
|
+
if lnum == 1 and rnum < 10:
|
|
76
|
+
return (rtext, rnum)
|
|
77
|
+
# stuff_zero logic between discontinous numbers
|
|
78
|
+
# http://www.hkame.org.hk/uploaded_files/magazine/15/271.pdf
|
|
79
|
+
with_zero = ("%s%s%s" % (ltext, self.select_text(
|
|
80
|
+
self.low_numwords[-1]), rtext), lnum + rnum)
|
|
81
|
+
no_zero = ("%s%s" % (ltext, rtext), lnum + rnum)
|
|
82
|
+
if len(str(lnum)) - len(str(rnum)) > 1:
|
|
83
|
+
if self.stuff_zero == 1: # 凡「零」必讀 All discontinous numbers
|
|
84
|
+
return with_zero
|
|
85
|
+
elif self.stuff_zero == 2: # Discontinous high numbers
|
|
86
|
+
if len(str(lnum)) - len(str(rnum)
|
|
87
|
+
) > 1 and len(str(rnum)) % 4 != 0:
|
|
88
|
+
return with_zero
|
|
89
|
+
return no_zero
|
|
90
|
+
elif self.stuff_zero == 3: # 凡「零」不讀 No zeros
|
|
91
|
+
return no_zero
|
|
92
|
+
elif rnum > lnum:
|
|
93
|
+
return ("%s%s" % (ltext, rtext), lnum * rnum)
|
|
94
|
+
return no_zero
|
|
95
|
+
|
|
96
|
+
def to_ordinal(self, value, counter="", reading=False, prefer=None):
|
|
97
|
+
self.set_str_selection(reading, prefer)
|
|
98
|
+
self.verify_ordinal(value)
|
|
99
|
+
base = self.to_cardinal(value, reading=reading, prefer=prefer)
|
|
100
|
+
return "%s%s%s" % (self.select_text(self.ord_prefix),
|
|
101
|
+
base, self.select_text(counter))
|
|
102
|
+
|
|
103
|
+
def to_ordinal_num(self, value, counter="", reading=False, prefer=None):
|
|
104
|
+
self.set_str_selection(reading, prefer)
|
|
105
|
+
return "%s%s%s" % (self.select_text(self.ord_prefix),
|
|
106
|
+
value, self.select_text(counter))
|
|
107
|
+
|
|
108
|
+
def to_year(self, value, reading=False, prefer=None):
|
|
109
|
+
self.set_str_selection(reading, prefer)
|
|
110
|
+
|
|
111
|
+
if not value == int(value):
|
|
112
|
+
raise TypeError(self.errmsg_floatyear % value)
|
|
113
|
+
|
|
114
|
+
out = []
|
|
115
|
+
if value < 0:
|
|
116
|
+
out += [self.year_prefix, self.year_bce]
|
|
117
|
+
elif reading == "capital":
|
|
118
|
+
out += [self.year_prefix]
|
|
119
|
+
|
|
120
|
+
out += [self.cards[int(s)] for s in str(abs(int(value)))]
|
|
121
|
+
out += [self.year]
|
|
122
|
+
|
|
123
|
+
return "".join(self.select_text(s) for s in out)
|
|
124
|
+
|
|
125
|
+
def to_currency(self, val, currency='XXX', cents=False, separator="",
|
|
126
|
+
adjective=False, reading=False, prefer=None):
|
|
127
|
+
"""
|
|
128
|
+
Args:
|
|
129
|
+
val: Numeric value
|
|
130
|
+
currency (str): Currency code
|
|
131
|
+
# cents (bool): Verbose cents
|
|
132
|
+
# separator (str): Cent separator
|
|
133
|
+
# adjective (bool): Prefix currency name with adjective
|
|
134
|
+
capital (bool): Select the capital form of a Chinese numeral
|
|
135
|
+
Returns:
|
|
136
|
+
str: Formatted string
|
|
137
|
+
|
|
138
|
+
Handles whole numbers and decimal numbers differently
|
|
139
|
+
"""
|
|
140
|
+
self.set_str_selection(reading, prefer)
|
|
141
|
+
left, right, is_negative = parse_currency_parts(
|
|
142
|
+
val, is_int_with_cents=False)
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
cr = self.CURRENCY_FORMS[currency]
|
|
146
|
+
# Not Applicable: ValueError
|
|
147
|
+
# CURRENCY_FLOATS are the generic terms for demicals
|
|
148
|
+
except KeyError:
|
|
149
|
+
raise NotImplementedError(
|
|
150
|
+
'Currency code "%s" not implemented for "%s"' %
|
|
151
|
+
(currency, self.__class__.__name__))
|
|
152
|
+
|
|
153
|
+
# CURRENCY_ADJECTIVES are not implemented
|
|
154
|
+
minus_str = self.negword if is_negative else ""
|
|
155
|
+
money_str = self.to_cardinal(left, reading=reading, prefer=prefer)
|
|
156
|
+
# has_decimal is not implemented
|
|
157
|
+
|
|
158
|
+
if currency == "XXX":
|
|
159
|
+
cr_pre, cr_post = ("", cr)
|
|
160
|
+
else:
|
|
161
|
+
cr_pre, cr_post = (cr, self.CURRENCY_FORMS["XXX"])
|
|
162
|
+
cents_str = self.to_currency_float(
|
|
163
|
+
right, reading=reading, prefer=prefer)
|
|
164
|
+
# Only add "整" in capital format
|
|
165
|
+
cheque = self.cheque_suffix if len(
|
|
166
|
+
cents_str) == 0 and reading == "capital" else ""
|
|
167
|
+
|
|
168
|
+
for c in [minus_str, money_str, cr_post, *cents_str, cheque]:
|
|
169
|
+
cr_pre += self.zh_to_cap(self.select_text(c), reading == "capital")
|
|
170
|
+
return cr_pre
|
|
171
|
+
|
|
172
|
+
def to_currency_float(self, value, reading=False, prefer=None):
|
|
173
|
+
cents = "%02d" % value
|
|
174
|
+
out = []
|
|
175
|
+
|
|
176
|
+
if int(cents) > 0:
|
|
177
|
+
if not (int(cents[0]) == 0 and reading == "capital"):
|
|
178
|
+
out += [self.cards[int(cents[0])]]
|
|
179
|
+
if int(cents[0]) > 0:
|
|
180
|
+
out += [self.CURRENCY_FLOATS[0]]
|
|
181
|
+
if int(cents[1]) > 0:
|
|
182
|
+
out += [self.cards[int(cents[1])], self.CURRENCY_FLOATS[1]]
|
|
183
|
+
|
|
184
|
+
return out
|
|
185
|
+
|
|
186
|
+
def zh_to_cap(self, value, capital):
|
|
187
|
+
"""
|
|
188
|
+
Select the capital form of a Chinese numeral
|
|
189
|
+
"""
|
|
190
|
+
out = value
|
|
191
|
+
one, ten = self.select_text(
|
|
192
|
+
self.cards[1]), self.select_text(
|
|
193
|
+
self.cards[10])
|
|
194
|
+
if capital:
|
|
195
|
+
for cap_w in self.CAP_map:
|
|
196
|
+
if cap_w[0] in out:
|
|
197
|
+
out = out.replace(cap_w[0], cap_w[1])
|
|
198
|
+
return out
|
|
199
|
+
elif out.startswith(one + ten):
|
|
200
|
+
out = out[len(one):]
|
|
201
|
+
return out
|
|
202
|
+
|
|
203
|
+
def setup(self):
|
|
204
|
+
self.precision = 2
|
|
205
|
+
self.negword = "負"
|
|
206
|
+
self.pointword = "點"
|
|
207
|
+
self.exclude_title = [self.negword, self.pointword]
|
|
208
|
+
self.errmsg_floatyear = "Cannot treat float %s as year."
|
|
209
|
+
|
|
210
|
+
self.reading = None
|
|
211
|
+
self.prefer = None
|
|
212
|
+
|
|
213
|
+
self.high_numwords = [
|
|
214
|
+
"萬", # 10 ** 4
|
|
215
|
+
"億", # 10 ** 8
|
|
216
|
+
"兆", # 10 ** 12
|
|
217
|
+
"京", # 10 ** 16
|
|
218
|
+
"垓", # 10 ** 20
|
|
219
|
+
"秭", # 10 ** 24
|
|
220
|
+
"穣", # 10 ** 28
|
|
221
|
+
"溝", # 10 ** 32
|
|
222
|
+
"澗", # 10 ** 36
|
|
223
|
+
"正", # 10 ** 40
|
|
224
|
+
"載", # 10 ** 44
|
|
225
|
+
"極", # 10 ** 48
|
|
226
|
+
"恆河沙", # 10 ** 52
|
|
227
|
+
"阿僧祇", # 10 ** 56
|
|
228
|
+
"那由他", # 10 ** 60
|
|
229
|
+
"不可思議", # 10 ** 64
|
|
230
|
+
"無量", # 10 ** 68
|
|
231
|
+
"不可說", # 10 ** 72
|
|
232
|
+
]
|
|
233
|
+
self.high_numwords.reverse()
|
|
234
|
+
|
|
235
|
+
self.mid_numwords = [
|
|
236
|
+
(1000, '千'),
|
|
237
|
+
(100, '百'),
|
|
238
|
+
(10, '十')
|
|
239
|
+
]
|
|
240
|
+
self.low_numwords = [
|
|
241
|
+
"九",
|
|
242
|
+
"八",
|
|
243
|
+
"七",
|
|
244
|
+
"六",
|
|
245
|
+
"五",
|
|
246
|
+
"四",
|
|
247
|
+
"三",
|
|
248
|
+
"二",
|
|
249
|
+
"一",
|
|
250
|
+
("零", "〇")
|
|
251
|
+
]
|
|
252
|
+
|
|
253
|
+
CAP_map = [
|
|
254
|
+
("千", "仟"),
|
|
255
|
+
("百", "佰"),
|
|
256
|
+
("十", "拾"),
|
|
257
|
+
("九", "玖"),
|
|
258
|
+
("八", "捌"),
|
|
259
|
+
("七", "柒"),
|
|
260
|
+
("六", "陸"),
|
|
261
|
+
("五", "伍"),
|
|
262
|
+
("四", "肆"),
|
|
263
|
+
("三", "叁"),
|
|
264
|
+
("二", "貳"),
|
|
265
|
+
("一", "壹"),
|
|
266
|
+
("元", "圓"),
|
|
267
|
+
("正", "整"),
|
|
268
|
+
]
|
|
269
|
+
|
|
270
|
+
def select_text(self, text):
|
|
271
|
+
"""Select the correct text from the Chinese, phonetic symbol (注音) or
|
|
272
|
+
alternatives ('ㄧ' or '壹')"""
|
|
273
|
+
if isinstance(text, strtype):
|
|
274
|
+
return text
|
|
275
|
+
if len(text) == 0:
|
|
276
|
+
return ''
|
|
277
|
+
# Check if reading is provided
|
|
278
|
+
if all(isinstance(item, tuple) for item in text):
|
|
279
|
+
if self.reading is True:
|
|
280
|
+
text = text[1]
|
|
281
|
+
else:
|
|
282
|
+
text = text[0]
|
|
283
|
+
|
|
284
|
+
# select the preferred one or the first one from multiple alternatives
|
|
285
|
+
if not isinstance(text, strtype):
|
|
286
|
+
common = set(text) & set(self.prefer or set())
|
|
287
|
+
if len(common) == 1:
|
|
288
|
+
text = common.pop()
|
|
289
|
+
else:
|
|
290
|
+
text = text[0]
|
|
291
|
+
return text
|
|
292
|
+
|
|
293
|
+
def set_str_selection(self, reading, prefer):
|
|
294
|
+
self.reading = reading
|
|
295
|
+
self.prefer = prefer
|
|
296
|
+
self.capital = reading == "capital"
|
num2words2/lang_ZH_CN.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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 .lang_ZH import Num2Word_ZH
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Num2Word_ZH_CN(Num2Word_ZH):
|
|
24
|
+
CURRENCY_FORMS = {
|
|
25
|
+
"XXX": "元", # Generic dollar
|
|
26
|
+
"CNY": "人民币",
|
|
27
|
+
"NTD": "新台币",
|
|
28
|
+
"HKD": "港币",
|
|
29
|
+
"MOP": "澳门币",
|
|
30
|
+
"SGD": "新加坡元",
|
|
31
|
+
"MYR": "马来西亚令吉",
|
|
32
|
+
"USD": "美元",
|
|
33
|
+
"EUR": "欧元",
|
|
34
|
+
"GBP": "英镑",
|
|
35
|
+
"JPY": "日元",
|
|
36
|
+
"CHF": "瑞士法郎",
|
|
37
|
+
"CAD": "加元",
|
|
38
|
+
"AUD": "澳币",
|
|
39
|
+
"NZD": "纽西兰元",
|
|
40
|
+
"THB": "泰铢",
|
|
41
|
+
"KRW": "韩元",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
def setup(self):
|
|
45
|
+
super().setup()
|
|
46
|
+
self.negword = "负"
|
|
47
|
+
self.pointword = "点"
|
|
48
|
+
self.exclude_title = [self.negword, self.pointword]
|
|
49
|
+
self.high_numwords = [
|
|
50
|
+
"万", # 10 ** 4
|
|
51
|
+
"亿", # 10 ** 8
|
|
52
|
+
"兆", # 10 ** 12
|
|
53
|
+
"京", # 10 ** 16
|
|
54
|
+
"垓", # 10 ** 20
|
|
55
|
+
"秭", # 10 ** 24
|
|
56
|
+
"穣", # 10 ** 28
|
|
57
|
+
"沟", # 10 ** 32
|
|
58
|
+
"涧", # 10 ** 36
|
|
59
|
+
"正", # 10 ** 40
|
|
60
|
+
"载", # 10 ** 44
|
|
61
|
+
"极", # 10 ** 48
|
|
62
|
+
"恒河沙", # 10 ** 52
|
|
63
|
+
"阿僧祇", # 10 ** 56
|
|
64
|
+
"那由他", # 10 ** 60
|
|
65
|
+
"不可思议", # 10 ** 64
|
|
66
|
+
"无量", # 10 ** 68
|
|
67
|
+
"不可说", # 10 ** 72
|
|
68
|
+
]
|
|
69
|
+
self.high_numwords.reverse()
|
|
70
|
+
|
|
71
|
+
CAP_map = [
|
|
72
|
+
("千", "仟"),
|
|
73
|
+
("百", "佰"),
|
|
74
|
+
("十", "拾"),
|
|
75
|
+
("九", "玖"),
|
|
76
|
+
("八", "捌"),
|
|
77
|
+
("七", "柒"),
|
|
78
|
+
("六", "陆"),
|
|
79
|
+
("五", "伍"),
|
|
80
|
+
("四", "肆"),
|
|
81
|
+
("三", "叁"),
|
|
82
|
+
("二", "贰"),
|
|
83
|
+
("一", "壹"),
|
|
84
|
+
("元", "圆"),
|
|
85
|
+
]
|