fnando / i18n

A small library to provide the I18n translations on the JavaScript.
https://fnando.github.io/i18n/
MIT License
169 stars 20 forks source link

Feature Request: Support delimited numbers for pluralization #98

Closed short-dsb closed 1 month ago

short-dsb commented 4 months ago

Description

Numbers passed to pluralize via count are not delimited. For example, in en-US:

1234 results

…should be:

1,234 results

Describe the solution

A possible solution is to pass an optional displayCount string that overrides the numeric count in the output. For example:

const resultsCount = 1234;

i18n.t("results", {
  count: resultsCount,
  displayCount: i18n.numberToDelimited(resultsCount),
});

This would give more control over how the output is formatted. For example, if someone wanted to use numberToHuman instead of numberToDelimited.

Alternatives you considered

There’s no alternative to this as far as I can tell, given how count is parsed when a string is pluralized via zero, one, few, many, and other. Happy to be proven wrong. 🙂

Additional context

This is how pluralization works for FBT via PluralOptions.value.

Thanks for all your work on this library!

loiclouvet commented 1 month ago

Does this solve your problem? @short-dsb https://github.com/fnando/i18n?tab=readme-ov-file#using-pluralization-and-number-formatting-together

short-dsb commented 1 month ago

It does, thank you. 🙂