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: add support for fr-BE #126

Merged
merged 5 commits into from
Sep 15, 2023
Merged

feat: add support for fr-BE #126

merged 5 commits into from
Sep 15, 2023

Conversation

victortaleb
Copy link
Contributor

Summary

In Belgium, we don't say "soixante-dix" or "quatre-vingt-dix" but "septante" and "nonante".

Potential improvements

  • I don't know if an option was the right call or if it should have been a separate language.

  • CH could also be useful for some people but I don't feel comfortable implementing it myself as I am not Swiss and it may be more complicated than I thought.

    Potential CH implementation
    --- a/lib/i18n/fr.js
    +++ b/lib/i18n/fr.js
    @@ -20,9 +20,9 @@ export class N2WordsFR extends BaseLanguage {
           [1000000n, 'million'],
           [1000n, 'mille'],
           [100n, 'cent'],
    -      ...(['BE'].includes(options.region) ? [[90n, 'nonante']] : []),
    -      [80n, 'quatre-vingts'],
    -      ...(['BE'].includes(options.region) ? [[70n, 'septante']] : []),
    +      ...(['BE', 'CH'].includes(options.region) ? [[90n, 'nonante']] : []),
    +      [80n, ['CH'].includes(options.region) ? 'huitante' : 'quatre-vingts'],
    +      ...(['BE', 'CH'].includes(options.region) ? [[70n, 'septante']] : []),
           [60n, 'soixante'],
           [50n, 'cinquante'],
           [40n, 'quarante'],
    @@ -77,7 +77,7 @@ export class N2WordsFR extends BaseLanguage {
           }
         }
         if (nNum < cNum && cNum < 100) {
    -      if (nNum % 10n == 1 && cNum != 80) return { [`${cText} et ${nText}`]: cNum + nNum };
    +      if (nNum % 10n == 1 && cText != 'quatre-vingt') return { [`${cText} et ${nText}`]: cNum + nNum };
           return { [`${cText}-${nText}`]: cNum + nNum };
         }
         if (nNum > cNum) return { [`${cText} ${nText}`]: cNum * nNum };

@forzagreen
Copy link
Owner

Hi @victortaleb , thanks for the contribution.
Indeed this is a very interesting topic.

👍 OK for the country code as 2 capital letters, which is compliant with ISO 3166-1 alpha-2.

I'm still thinking on how to represent the feature. 2 options are possible:

  1. Your suggestion with {region: 'BE'} (or {country: 'BE'})
  2. Appending the region name after the language code, as fr-BE or fr_BE. This is the approach used by our cousin package num2words (python equivalent):
    You can supply values like fr_FR; if the country doesn't exist but the language does, the code will fall back to the base language (i.e. fr).

@forzagreen forzagreen added the enhancement New feature or request label Sep 14, 2023
@victortaleb
Copy link
Contributor Author

Option 2 would probably be better if there are languages with significantly different dialects.

Here is an implementation.
To keep things DRY, I kept the region option but prefixed with an _ to show that it should only be used internally.
I went with fr-BE as I never saw fr_BE before. Feel free to change it if you want to.

@forzagreen
Copy link
Owner

That's great @victortaleb . Thank you for your contribution !

@forzagreen forzagreen merged commit 743fdf6 into forzagreen:master Sep 15, 2023
8 checks passed
@forzagreen
Copy link
Owner

Released in v1.18.0 🎆

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

Successfully merging this pull request may close these issues.

2 participants