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

feat(locales): spanish support added #1105

Closed
wants to merge 2 commits into from
Closed

Conversation

ohmmolina
Copy link
Contributor

Support for Spain and Mexico.

Issue: Optimized for currencies, numbers ending in 1 are showed as "Un" instead of "Uno"

Support for Spain and Mexico.

Issue: Optimized for currencies, numbers ending in 1 are showed as "Un" instead of "Uno"
Replace "One Dollars Only" for "One Dollar Only". It works for al amounts equals to 1
@mastermunj
Copy link
Owner

Thank you for your contribution @ohmmolina.

There are a few failing tests. Please have a look at them.

@s1gtrap
Copy link
Contributor

s1gtrap commented Jul 14, 2024

@mastermunj I'm not sure how to go about this, while I don't speak Spanish (I'm learning bit by bit) I do need this for a project, and because this PR seems to have gone stale, I went ahead and fixed the remaining issues which is downstream here.

I don't mean to steal credit from @ohmmolina (they're still credited as the author of the brunt of the work: s1gtrap/to-words@0ec0204), but should I submit a new PR?

The primary addition is the notion of a 'trailing' word. According to point 2.2 of 'uno' in Diccionario panhispánico de dudas describing cardinals:

2.2. Cuando el numeral uno se antepone a un sustantivo masculino, se apocopa en la forma un: No quedó ni un soldado vivo. Ante sustantivos femeninos que comienzan por /a/ tónica, el femenino una suele hoy apocoparse: Se repartió un arma a cada hombre (aunque no se considera incorrecto, hoy es infrecuente en estos casos el uso de la forma plena una). Estas mismas leyes de la apócope rigen cuando el numeral uno, una es componente de otros adjetivos numerales, escritos en una o en varias palabras: Tengo veintiún años; Hasta ahora ha escrito treinta y una novelas; Ha reunido una colección de cuarenta y un(a) hachas. [..]

https://www.rae.es/dpd/uno

I.e. 'uno' immediately prior to a masculine noun (such as millon, billon and trillon) is shortened to 'un', hence the only case when it should be 'uno' is when it's the last word (this doesn't account for feminine substantives, but it's my impression that gender is out of scope of this library).

Obviously this is a bit awkward with the recursion, but I believe I solved it by passing trailing: true in certain cases. If trailing is true and the exactWordsMapping is of the tuple type [string, string], the latter entry of the mapping is used instead of the former.

If there is a better solution that didn't occur to me please let me know and I'd be down to try and fix it in such a manner instead as this only further complicates the algorithm, but I did have a look at French (as that's the only other romance language) but didn't have much luck since one is literally just 'un' everywhere.

@ohmmolina
Copy link
Contributor Author

Hi, @s1gtrap. Thank you for your interest about my language.
I could suggest to create a new PR. And thank you for the credit.

The main reason why this PR is not acepted, is not because of Spanish, but because I can't found a way to define how to not use plurals when the number to convert is just one. In USD, for example, it shows "One Dollars Only", but should shows "One Dollar Only".

Anyway, you should made another PR. Let me know when you do and I would close this one.

@s1gtrap
Copy link
Contributor

s1gtrap commented Jul 15, 2024

Yea I noticed you addressed that in 6971009, but it would appear that was fixed on main in 5c34a6a almost a year later, so I just adapted to that instead.

Really appreciate you signing off on this after 1.5 years! I'll get to the PR, let's get this into main! :)

@mastermunj
Copy link
Owner

Thank you @ohmmolina and @s1gtrap. Your contributions are well appreciated!

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