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

Plural ranges #529

Closed
karimshalapy opened this issue Sep 24, 2023 · 5 comments
Closed

Plural ranges #529

karimshalapy opened this issue Sep 24, 2023 · 5 comments
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@karimshalapy
Copy link
Contributor

Is your feature request related to a problem? Please describe.

In Arabic we have different forms of the plural word for different ranges of the number (for more information check here).

Usually the ranges are:

  • Singular (1),
  • Double (2)
  • Broken Plural (3:10)
  • Singular (>10)

Example using the word Book in Arabic:

  • كتاب
  • كتابان
  • 3 كتب
  • 11 كتاب

I tried to dig in the code and found nothing, and it wasn't mentioned in the docs, so I don't know if this feature exists, that's why I opened this ticket.

Describe the solution you'd like

So to decrease repetition, can we add a feature where we can define ranges of numbers not only single number while defining the different plural translations.

Proposed solutions:

  1. "{variable, plural, =1 {One Plural} =3:10 {# Plurals} other {# Other Plural Form}}" (best DX)
  2. "{variable, plural, =1 {One Plural} =3-10 {# Plurals} other {# Other Plural Form}}" (decent DX)
  3. "{variable, plural, =1 {One Plural} =3 =4 =5 =6 =7 =8 =9 =10 {# Plurals} other {# Other Plural Form}}" (not so good DX, but definitely better than nothing)

Describe alternatives you've considered

To be able to do this now it will require a ton of repetition:

"{variable, plural, =1 {One Plural} =3 {# Plurals} =4 {# Plurals} =5 {# Plurals} =6 {# Plurals} =7 {# Plurals} =8 {# Plurals} =9 {# Plurals} =10 {# Plurals} other {# Other Plural Form}}"
@karimshalapy karimshalapy added enhancement New feature or request unconfirmed Needs triage. labels Sep 24, 2023
@amannn
Copy link
Owner

amannn commented Sep 25, 2023

Thanks for great question! We use the ICU parser from Format.JS currently, so we support all of these: https://formatjs.io/docs/core-concepts/icu-syntax#plural-format

This is obviously missing in the docs though (same for selectordinal). In your case, I guess "few" should be the right category. Can you confirm that this works? If so, would you by chance be interested in adding this information to the docs?

@karimshalapy
Copy link
Contributor Author

@amannn Oh, Thanks for the prompt reply.
It definitely helps and you're correct the few keyword will resolve this feature request.

I think it might be worth adding that link to the docs as quick solution, until further enhancements down the road..

@amannn
Copy link
Owner

amannn commented Sep 25, 2023

Yep, we should absolutely include that list of possible options both for plural as well as selectordinal. Would you by chance be interested in opening a PR? Otherwise I can try to look into it.

@karimshalapy
Copy link
Contributor Author

After my working day today, I'll make the time to open a PR with the documentation.
What do you have in mind regarding this? I thought about saying that it uses FormatJS under the hood and references some links here and there.

@amannn
Copy link
Owner

amannn commented Sep 25, 2023

That's very kind, thanks!

We tend to avoid external links by now when the content is important and not supplemental. E.g. for the date formats we have a table that contains all valid symbols: https://next-intl-docs.vercel.app/docs/usage/dates-times#dates-and-times-within-messages

I think similarly to this, we could include the list of supported pluralization forms.

Maybe we'll switch the parser at some point, I think this documentation could also be helpful to ensure we continue to support the same use cases.

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

No branches or pull requests

2 participants