Skip to content

Commit 038e92d

Browse files
Merge pull request #565 from randall-vx/master-dev-es-cr-randallvx
[ADD] num2words: es_CR language added
2 parents 974f7a8 + d63741d commit 038e92d

File tree

5 files changed

+100
-6
lines changed

5 files changed

+100
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist
66
/.tox
77
.eggs/
88
/venv/
9+
.venv/

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Besides the numerical argument, there are two main optional arguments, ``to:`` a
8888
* ``en_NG`` (English - Nigeria)
8989
* ``es`` (Spanish)
9090
* ``es_CO`` (Spanish - Colombia)
91+
* ``es_CR`` (Spanish - Costa Rica)
9192
* ``es_VE`` (Spanish - Venezuela)
9293
* ``es_GT`` (Spanish - Guatemala)
9394
* ``eu`` (EURO)

num2words/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
from . import (lang_AM, lang_AR, lang_AZ, lang_BY, lang_CZ, lang_DE, lang_DK,
2121
lang_EN, lang_EN_IN, lang_EN_NG, lang_EO, lang_ES, lang_ES_CO,
22-
lang_ES_GT, lang_ES_NI, lang_ES_VE, lang_FA, lang_FI, lang_FR,
23-
lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE, lang_HU, lang_ID,
24-
lang_IS, lang_IT, lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT,
25-
lang_LV, lang_NL, lang_NO, lang_PL, lang_PT, lang_PT_BR,
26-
lang_RO, lang_RU, lang_SK, lang_SL, lang_SR, lang_SV, lang_TE,
27-
lang_TG, lang_TH, lang_TR, lang_UK, lang_VI)
22+
lang_ES_CR, lang_ES_GT, lang_ES_NI, lang_ES_VE, lang_FA,
23+
lang_FI, lang_FR, lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE,
24+
lang_HU, lang_ID, lang_IS, lang_IT, lang_JA, lang_KN, lang_KO,
25+
lang_KZ, lang_LT, lang_LV, lang_NL, lang_NO, lang_PL, lang_PT,
26+
lang_PT_BR, lang_RO, lang_RU, lang_SK, lang_SL, lang_SR,
27+
lang_SV, lang_TE, lang_TG, lang_TH, lang_TR, lang_UK, lang_VI)
2828

2929
CONVERTER_CLASSES = {
3030
'am': lang_AM.Num2Word_AM(),
@@ -45,6 +45,7 @@
4545
'eo': lang_EO.Num2Word_EO(),
4646
'es': lang_ES.Num2Word_ES(),
4747
'es_CO': lang_ES_CO.Num2Word_ES_CO(),
48+
'es_CR': lang_ES_CR.Num2Word_ES_CR(),
4849
'es_GT': lang_ES_GT.Num2Word_ES_GT(),
4950
'es_NI': lang_ES_NI.Num2Word_ES_NI(),
5051
'es_VE': lang_ES_VE.Num2Word_ES_VE(),

num2words/lang_ES_CR.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
# Copyright (c) 2024, Randall Castro. All Rights Reserved.
5+
6+
# This library is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
# MA 02110-1301 USA
18+
19+
from __future__ import print_function, unicode_literals
20+
21+
from .lang_ES import Num2Word_ES
22+
23+
24+
class Num2Word_ES_CR(Num2Word_ES):
25+
26+
def to_currency(self, val, longval=True, old=False):
27+
result = self.to_splitnum(val, hightxt="colón/es", lowtxt="céntimo/s",
28+
divisor=1, jointxt="y", longval=longval)
29+
# Handle exception, in spanish is "un euro" and not "uno euro"
30+
return result.replace("uno", "un")

tests/test_es_cr.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
# Copyright (c) 2024, Randall Castro. All Rights Reserved.
5+
6+
# This library is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
# MA 02110-1301 USA
18+
19+
from __future__ import unicode_literals
20+
21+
from num2words import num2words
22+
23+
from . import test_es
24+
25+
TEST_CASES_TO_CURRENCY = (
26+
(1, 'un colón'),
27+
(2, 'dos colónes'),
28+
(8, 'ocho colónes'),
29+
(12, 'doce colónes'),
30+
(21, 'veintiun colónes'),
31+
(81.25, 'ochenta y un colónes y veinticinco céntimos'),
32+
(100, 'cien colónes'),
33+
)
34+
35+
36+
class Num2WordsESCOTest(test_es.Num2WordsESTest):
37+
38+
def test_number(self):
39+
for test in test_es.TEST_CASES_CARDINAL:
40+
self.assertEqual(num2words(test[0], lang='es_CR'), test[1])
41+
42+
def test_ordinal(self):
43+
for test in test_es.TEST_CASES_ORDINAL:
44+
self.assertEqual(
45+
num2words(test[0], lang='es_CR', ordinal=True),
46+
test[1]
47+
)
48+
49+
def test_ordinal_num(self):
50+
for test in test_es.TEST_CASES_ORDINAL_NUM:
51+
self.assertEqual(
52+
num2words(test[0], lang='es', to='ordinal_num'),
53+
test[1]
54+
)
55+
56+
def test_currency(self):
57+
for test in TEST_CASES_TO_CURRENCY:
58+
self.assertEqual(
59+
num2words(test[0], lang='es_CR', to='currency'),
60+
test[1]
61+
)

0 commit comments

Comments
 (0)