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

Add _zero suffix lookup if count === 0 #1705

Merged
merged 1 commit into from Dec 8, 2021

Conversation

kgominyuk
Copy link
Contributor

@kgominyuk kgominyuk commented Dec 7, 2021

Localizing in a specific way 0 count is a very common case.
There was a related issue.
Also unicode documentation says: "implementations are encouraged to provide the ability to have special plural messages for 0 in particular, so that more natural language can be used" https://cldr.unicode.org/index/cldr-spec/plural-rules

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included

Checklist (for documentation change)

  • only relevant documentation part is changed (make a diff before you submit the PR)
  • motivation/reason is provided

@adrai
Copy link
Member

@adrai adrai commented Dec 7, 2021

Currently it's what the Intl plural resolves to...

I don't know if we should introduce a special zero handling...

What do you think @jamuhl?

@kgominyuk
Copy link
Contributor Author

@kgominyuk kgominyuk commented Dec 7, 2021

@jamuhl
Copy link
Member

@jamuhl jamuhl commented Dec 7, 2021

For me ok...as it's a rather common use case. But I think the check should add && (pluralSuffix === 'one' || pluralSuffix === 'other') to avoid using it with v3 and using it on languages like chinese where the only used form is other

@kgominyuk
Copy link
Contributor Author

@kgominyuk kgominyuk commented Dec 7, 2021

I added this.pluralResolver.shouldUseIntlApi() into condition to avoid using it with v3.
Adding && (pluralSuffix === 'one' || pluralSuffix === 'other') won't prevent zero lookup for chinese.

Why you think that this is irrelevant for chinese?

The goal of this change is to provide the ability to use more natural language:
None of your friends are online. instead of You have 0 friends online.

This is also actual for chinese.

@jamuhl
Copy link
Member

@jamuhl jamuhl commented Dec 7, 2021

It's a guess that chinese as it has only one plural form does not have a thing like zero, one, other at all...but idk...I'm not capable of speaking any asian language

but you're right...the check won't work anyway...as the suffix is other

@kgominyuk
Copy link
Contributor Author

@kgominyuk kgominyuk commented Dec 7, 2021

Also want to mention that this pr isn't introduce requirement to add _zero entries for all localized keys.
If the count is zero, and a _zero entry is present, then it will be used.
If _zero entry isn't present, original plural suffix will be used.

@coveralls
Copy link

@coveralls coveralls commented Dec 7, 2021

Coverage Status

Coverage increased (+0.06%) to 90.941% when pulling d48a453 on kgominyuk:zero-suffix-support into 22a45fa on i18next:master.

@adrai
Copy link
Member

@adrai adrai commented Dec 7, 2021

needs to be documented somewhere

@adrai adrai merged commit 91ae0f4 into i18next:master Dec 8, 2021
2 of 4 checks passed
@adrai
Copy link
Member

@adrai adrai commented Dec 8, 2021

Thank you for your contribution, it's included in v21.6.0

@kgominyuk kgominyuk deleted the zero-suffix-support branch Dec 8, 2021
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

4 participants