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_FO.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
|
+
# Faroese language support
|
|
24
|
+
class Num2Word_FO(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'DKK': (('króna', 'krónur'), ('oyra', 'oyru')),
|
|
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 = ['', 'ein', 'tvey', 'trý', 'fýra', 'fimm', 'seks', 'sjey', 'átta', 'níggju']
|
|
35
|
+
self.tens = ['', 'tíggju', 'tjúgu', 'tríati', 'fjøruti', 'fimmti', 'seksti', 'sjeyti', 'áttati', 'níti']
|
|
36
|
+
self.hundred = "hundrað"
|
|
37
|
+
self.thousand = "túsund"
|
|
38
|
+
self.million = "millión"
|
|
39
|
+
|
|
40
|
+
def to_cardinal(self, number):
|
|
41
|
+
"""Convert a number to its word representation in Faroese."""
|
|
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 Faroese."""
|
|
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 Faroese."""
|
|
101
|
+
cardinal = self.to_cardinal(number)
|
|
102
|
+
# Language-specific ordinal suffix
|
|
103
|
+
return cardinal + "-ti"
|
|
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 Faroese."""
|
|
111
|
+
return self.to_cardinal(val)
|
|
112
|
+
|
|
113
|
+
def to_currency(self, val, currency='DKK', cents=True, separator=' ', adjective=False):
|
|
114
|
+
"""Convert to currency in Faroese."""
|
|
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_FR.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
from .lang_EUR import Num2Word_EUR
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Num2Word_FR(Num2Word_EUR):
|
|
24
|
+
CURRENCY_FORMS = {
|
|
25
|
+
'EUR': (('euro', 'euros'), ('centime', 'centimes')),
|
|
26
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents')),
|
|
27
|
+
'FRF': (('franc', 'francs'), ('centime', 'centimes')),
|
|
28
|
+
'GBP': (('livre', 'livres'), ('penny', 'pence')),
|
|
29
|
+
'CNY': (('yuan', 'yuans'), ('fen', 'jiaos')),
|
|
30
|
+
'JPY': (('yen', 'yens'), ('sen', 'sens')),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def setup(self):
|
|
34
|
+
Num2Word_EUR.setup(self)
|
|
35
|
+
|
|
36
|
+
self.negword = "moins "
|
|
37
|
+
self.pointword = "virgule"
|
|
38
|
+
self.errmsg_nonnum = (
|
|
39
|
+
u"Seulement des nombres peuvent être convertis en mots."
|
|
40
|
+
)
|
|
41
|
+
self.errmsg_toobig = (
|
|
42
|
+
u"Nombre trop grand pour être converti en mots (abs(%s) > %s)."
|
|
43
|
+
)
|
|
44
|
+
self.exclude_title = ["et", "virgule", "moins"]
|
|
45
|
+
self.mid_numwords = [(1000, "mille"), (100, "cent"),
|
|
46
|
+
(80, "quatre-vingts"), (60, "soixante"),
|
|
47
|
+
(50, "cinquante"), (40, "quarante"),
|
|
48
|
+
(30, "trente")]
|
|
49
|
+
self.low_numwords = ["vingt", "dix-neuf", "dix-huit", "dix-sept",
|
|
50
|
+
"seize", "quinze", "quatorze", "treize", "douze",
|
|
51
|
+
"onze", "dix", "neuf", "huit", "sept", "six",
|
|
52
|
+
"cinq", "quatre", "trois", "deux", "un", "zéro"]
|
|
53
|
+
self.ords = {
|
|
54
|
+
"cinq": "cinquième",
|
|
55
|
+
"neuf": "neuvième",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
def merge(self, curr, next):
|
|
59
|
+
ctext, cnum, ntext, nnum = curr + next
|
|
60
|
+
|
|
61
|
+
if cnum == 1:
|
|
62
|
+
if nnum < 1000000:
|
|
63
|
+
return next
|
|
64
|
+
else:
|
|
65
|
+
if (not (cnum - 80) % 100
|
|
66
|
+
or (not cnum % 100 and cnum < 1000))\
|
|
67
|
+
and nnum < 1000000 \
|
|
68
|
+
and ctext[-1] == "s":
|
|
69
|
+
ctext = ctext[:-1]
|
|
70
|
+
if cnum < 1000 and nnum != 1000 and \
|
|
71
|
+
ntext[-1] != "s" and not nnum % 100:
|
|
72
|
+
ntext += "s"
|
|
73
|
+
|
|
74
|
+
if nnum < cnum < 100:
|
|
75
|
+
if nnum % 10 == 1 and cnum != 80:
|
|
76
|
+
return ("%s-et-%s" % (ctext, ntext), cnum + nnum)
|
|
77
|
+
return ("%s-%s" % (ctext, ntext), cnum + nnum)
|
|
78
|
+
if nnum > cnum:
|
|
79
|
+
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
|
80
|
+
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
|
81
|
+
|
|
82
|
+
# Is this right for such things as 1001 - "mille unième" instead of
|
|
83
|
+
# "mille premier"?? "millième"??
|
|
84
|
+
|
|
85
|
+
def to_ordinal(self, value):
|
|
86
|
+
self.verify_ordinal(value)
|
|
87
|
+
if value == 1:
|
|
88
|
+
return "premier"
|
|
89
|
+
word = self.to_cardinal(value)
|
|
90
|
+
for src, repl in self.ords.items():
|
|
91
|
+
if word.endswith(src):
|
|
92
|
+
word = word[:-len(src)] + repl
|
|
93
|
+
break
|
|
94
|
+
else:
|
|
95
|
+
if word[-1] == "e":
|
|
96
|
+
word = word[:-1]
|
|
97
|
+
word = word + "ième"
|
|
98
|
+
return word
|
|
99
|
+
|
|
100
|
+
def to_ordinal_num(self, value):
|
|
101
|
+
self.verify_ordinal(value)
|
|
102
|
+
out = str(value)
|
|
103
|
+
out += "er" if value == 1 else "me"
|
|
104
|
+
return out
|
|
105
|
+
|
|
106
|
+
def to_currency(self, val, currency='EUR', cents=True, separator=' et',
|
|
107
|
+
adjective=False):
|
|
108
|
+
# Handle integers specially - just add currency name without cents
|
|
109
|
+
if isinstance(val, int):
|
|
110
|
+
try:
|
|
111
|
+
cr1, cr2 = self.CURRENCY_FORMS[currency]
|
|
112
|
+
except KeyError:
|
|
113
|
+
# Fallback to base implementation for unknown currency
|
|
114
|
+
return self.to_cardinal(val)
|
|
115
|
+
|
|
116
|
+
minus_str = "%s " % self.negword.strip() if val < 0 else ""
|
|
117
|
+
abs_val = abs(val)
|
|
118
|
+
money_str = self.to_cardinal(abs_val)
|
|
119
|
+
|
|
120
|
+
# Proper pluralization for currency
|
|
121
|
+
# In French, 0 and 1 use singular
|
|
122
|
+
if abs_val <= 1:
|
|
123
|
+
currency_str = cr1[0] # singular
|
|
124
|
+
else:
|
|
125
|
+
currency_str = cr1[1] if len(cr1) > 1 else cr1[0] # plural
|
|
126
|
+
|
|
127
|
+
return u'%s%s %s' % (minus_str, money_str, currency_str)
|
|
128
|
+
|
|
129
|
+
# For floats, use the original implementation
|
|
130
|
+
result = super(Num2Word_FR, self).to_currency(
|
|
131
|
+
val, currency=currency, cents=cents, separator=separator,
|
|
132
|
+
adjective=adjective)
|
|
133
|
+
return result
|
num2words2/lang_FR_BE.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
from .lang_FR import Num2Word_FR
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Num2Word_FR_BE(Num2Word_FR):
|
|
24
|
+
def setup(self):
|
|
25
|
+
Num2Word_FR.setup(self)
|
|
26
|
+
|
|
27
|
+
self.mid_numwords = [(1000, "mille"), (100, "cent"), (90, "nonante"),
|
|
28
|
+
(80, "quatre-vingt"), (70, "septante"),
|
|
29
|
+
(60, "soixante"), (50, "cinquante"),
|
|
30
|
+
(40, "quarante"), (30, "trente")]
|
|
31
|
+
|
|
32
|
+
def merge(self, curr, next):
|
|
33
|
+
ctext, cnum, ntext, nnum = curr + next
|
|
34
|
+
|
|
35
|
+
if cnum == 1:
|
|
36
|
+
if nnum < 1000000:
|
|
37
|
+
return next
|
|
38
|
+
|
|
39
|
+
if cnum < 1000 and nnum != 1000 and\
|
|
40
|
+
ntext[-1] != "s" and not nnum % 100:
|
|
41
|
+
ntext += "s"
|
|
42
|
+
|
|
43
|
+
if nnum < cnum < 100:
|
|
44
|
+
if nnum % 10 == 1:
|
|
45
|
+
return ("%s et %s" % (ctext, ntext), cnum + nnum)
|
|
46
|
+
return ("%s-%s" % (ctext, ntext), cnum + nnum)
|
|
47
|
+
if nnum > cnum:
|
|
48
|
+
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
|
49
|
+
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
num2words2/lang_FR_CH.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
from __future__ import print_function, unicode_literals
|
|
18
|
+
|
|
19
|
+
from .lang_FR import Num2Word_FR
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Num2Word_FR_CH(Num2Word_FR):
|
|
23
|
+
def setup(self):
|
|
24
|
+
Num2Word_FR.setup(self)
|
|
25
|
+
|
|
26
|
+
self.mid_numwords = [(1000, "mille"), (100, "cent"), (90, "nonante"),
|
|
27
|
+
(80, "huitante"), (70, "septante"),
|
|
28
|
+
(60, "soixante"), (50, "cinquante"),
|
|
29
|
+
(40, "quarante"), (30, "trente")]
|
|
30
|
+
|
|
31
|
+
def merge(self, curr, next):
|
|
32
|
+
ctext, cnum, ntext, nnum = curr + next
|
|
33
|
+
|
|
34
|
+
if cnum == 1:
|
|
35
|
+
if nnum < 1000000:
|
|
36
|
+
return next
|
|
37
|
+
|
|
38
|
+
if cnum < 1000 and nnum != 1000 and\
|
|
39
|
+
ntext[-1] != "s" and not nnum % 100:
|
|
40
|
+
ntext += "s"
|
|
41
|
+
|
|
42
|
+
if nnum < cnum < 100:
|
|
43
|
+
if nnum % 10 == 1:
|
|
44
|
+
return ("%s et %s" % (ctext, ntext), cnum + nnum)
|
|
45
|
+
return ("%s-%s" % (ctext, ntext), cnum + nnum)
|
|
46
|
+
if nnum > cnum:
|
|
47
|
+
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
|
48
|
+
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
num2words2/lang_FR_DZ.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 .lang_FR import Num2Word_FR
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Num2Word_FR_DZ(Num2Word_FR):
|
|
24
|
+
CURRENCY_FORMS = {
|
|
25
|
+
'DZD': (('dinar', 'dinars'), ('centime', 'centimes')),
|
|
26
|
+
'EUR': (('euro', 'euros'), ('centime', 'centimes')),
|
|
27
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents')),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def to_currency(self, val, currency='DZD', cents=True, separator=' et',
|
|
31
|
+
adjective=False):
|
|
32
|
+
result = super(Num2Word_FR, self).to_currency(
|
|
33
|
+
val, currency=currency, cents=cents, separator=separator,
|
|
34
|
+
adjective=adjective)
|
|
35
|
+
return result
|
num2words2/lang_GL.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
|
+
# Galician language support
|
|
24
|
+
class Num2Word_GL(Num2Word_Base):
|
|
25
|
+
CURRENCY_FORMS = {
|
|
26
|
+
'EUR': (('euro', 'euros'), ('céntimo', 'céntimos')),
|
|
27
|
+
'USD': (('dollar', 'dollars'), ('cent', 'cents'))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def setup(self):
|
|
31
|
+
self.negword = "minus "
|
|
32
|
+
self.pointword = "point"
|
|
33
|
+
self.ones = ['', 'un', 'dous', 'tres', 'catro', 'cinco', 'seis', 'sete', 'oito', 'nove']
|
|
34
|
+
self.tens = ['', 'dez', 'vinte', 'trinta', 'corenta', 'cincuenta', 'sesenta', 'setenta', 'oitenta', 'noventa']
|
|
35
|
+
self.hundred = "cento"
|
|
36
|
+
self.thousand = "mil"
|
|
37
|
+
self.million = "millón"
|
|
38
|
+
|
|
39
|
+
def to_cardinal(self, number):
|
|
40
|
+
"""Convert a number to its word representation in Galician."""
|
|
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 Galician."""
|
|
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 Galician."""
|
|
100
|
+
cardinal = self.to_cardinal(number)
|
|
101
|
+
# Language-specific ordinal suffix
|
|
102
|
+
return cardinal + "-o"
|
|
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 Galician."""
|
|
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 Galician."""
|
|
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()
|