Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change implementation of to_currency() in es_ES #167

Merged
merged 3 commits into from Apr 18, 2018

Conversation

Abranes
Copy link
Contributor

@Abranes Abranes commented Apr 16, 2018

Fixes # by @Abranes (abraham@studio73.es)

Changes proposed in this pull request:

  • Update es_ES to new implementation of the to_currency()
  • Change some spanish translations (in spanish 'cent' isn't 'centavos' is 'centimos' and the old currency is 'pesetas' not 'pesos')

Status

  • READY
  • HOLD
  • WIP (Work-In-Progress)

How to verify this change

import num2words
a = 1234.01
print num2words.num2words(a, to='currency', lang='es_ES')
mil doscientos treinta y cuatro euros con un centimo

Additional notes

@coveralls
Copy link

coveralls commented Apr 16, 2018

Coverage Status

Coverage increased (+0.006%) to 89.632% when pulling 45ec843 on Studio73:fix-lang-es_ES into 551a980 on savoirfairelinux:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.625% when pulling ca8def5 on Studio73:fix-lang-es_ES into 551a980 on savoirfairelinux:master.

@erozqba
Copy link
Collaborator

erozqba commented Apr 18, 2018

@Abranes thanks a lot for this PR.

This should help us to remove redundant classes created to have currency for other countries, example lang_ES_VE.py, after this is merged we could refactor this classes to add only the proper CURREMCY_FORMS and probably add a notice of depreciation in the future because it will be easier to have this all this CURRENCY_FORMS in the lang_ES.py file only.

I would like to suggest you the following changes:

diff --git a/num2words/lang_ES.py b/num2words/lang_ES.py
index 4902a8f..a123776 100644
--- a/num2words/lang_ES.py
+++ b/num2words/lang_ES.py
@@ -25,6 +25,7 @@ class Num2Word_ES(Num2Word_EU):
     CURRENCY_FORMS = {
         'EUR': (('euro', 'euros'), ('centimo', 'centimos')),
         'ESP': (('peseta', 'pesetas'), ('centimo', 'centimos')),
+        'USD': (('dolar', 'dolares'), ('centavo', 'centavos')),
     }
 
     # //CHECK: Is this sufficient??
@@ -171,9 +172,7 @@ class Num2Word_ES(Num2Word_EU):
         return "%s%s" % (value, "º" if self.gender_stem == 'o' else "ª")
 
     def to_currency(self, val, currency='EUR', cents=True, seperator=' con',
-                    adjective=False, old=False):
-        if old:
-            currency = 'ESP'
+                    adjective=False):
         result = super(Num2Word_ES, self).to_currency(
             val, currency=currency, cents=cents, seperator=seperator,
             adjective=adjective)
diff --git a/tests/test_es.py b/tests/test_es.py
index 415d78e..c16fb46 100644
--- a/tests/test_es.py
+++ b/tests/test_es.py
@@ -120,7 +120,7 @@ TEST_CASES_TO_CURRENCY = (
     (100.00, 'cien euros con cero centimos'),
 )
 
-TEST_CASES_TO_CURRENCY_OLD = (
+TEST_CASES_TO_CURRENCY_ESP = (
     (1.00, 'un peseta con cero centimos'),
     (2.00, 'dos pesetas con cero centimos'),
     (8.00, 'ocho pesetas con cero centimos'),
@@ -132,6 +132,18 @@ TEST_CASES_TO_CURRENCY_OLD = (
 )
 
 
+TEST_CASES_TO_CURRENCY_USD = (
+    (1.00, 'un dolar con cero centavos'),
+    (2.00, 'dos dolares con cero centavos'),
+    (8.00, 'ocho dolares con cero centavos'),
+    (12.00, 'doce dolares con cero centavos'),
+    (21.00, 'veintiun dolares con cero centavos'),
+    (81.25, 'ochenta y un dolares con veinticinco centavos'),
+    (350.90, 'trescientos cincuenta dolares con noventa centavos'),
+    (100.00, 'cien dolares con cero centavos'),
+)
+
+
 class Num2WordsESTest(TestCase):
 
     def test_number(self):
@@ -160,8 +172,15 @@ class Num2WordsESTest(TestCase):
             )
 
     def test_currency_old(self):
-        for test in TEST_CASES_TO_CURRENCY_OLD:
+        for test in TEST_CASES_TO_CURRENCY_ESP:
             self.assertEqual(
                 num2words(test[0], lang='es', to='currency', old=True),
                 test[1]
             )
+
+    def test_currency_usd(self):
+        for test in TEST_CASES_TO_CURRENCY_USD:
+            self.assertEqual(
+                num2words(test[0], lang='es', to='currency', currency='USD'),
+                test[1]
+            )
(END)

@erozqba erozqba mentioned this pull request Apr 18, 2018
3 tasks
@Abranes
Copy link
Contributor Author

Abranes commented Apr 18, 2018

@erozqba Done!

@erozqba
Copy link
Collaborator

erozqba commented Apr 18, 2018

👍

@erozqba erozqba merged commit b492530 into savoirfairelinux:master Apr 18, 2018
@fuentes73 fuentes73 deleted the fix-lang-es_ES branch April 18, 2018 13:54
@Abranes
Copy link
Contributor Author

Abranes commented Apr 18, 2018

@erozqba ¿When will be generated a new release?

@erozqba
Copy link
Collaborator

erozqba commented Apr 18, 2018

@Abranes I will try to find some time to make a new release, I will like to have the other open PR merged before to make the new release too. Could you help reviewing the other PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants