Closed victortaleb closed 1 year ago
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:
{region: 'BE'}
(or {country: 'BE'}
)fr-BE
or fr_BE
. This is the approach used by our cousin package num2words (python equivalent):
_You can supply values like frFR; if the country doesn't exist but the language does, the code will fall back to the base language (i.e. fr).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.
That's great @victortaleb . Thank you for your contribution !
Released in v1.18.0 🎆
Summary
In Belgium, we don't say "soixante-dix" or "quatre-vingt-dix" but "septante" and "nonante".
Potential improvements
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
```diff --- 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 }; ```