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 behavior with count == 0 #1982

Closed
4 tasks done
H3llK33p3r opened this issue Oct 2, 2024 · 2 comments
Closed
4 tasks done

Plural behavior with count == 0 #1982

H3llK33p3r opened this issue Oct 2, 2024 · 2 comments
Labels
Status: Review Needed Request for review comments

Comments

@H3llK33p3r
Copy link

Reporting a bug?

Using the example in the documentation with 'car' and 'apple' : https://vue-i18n.intlify.dev/guide/essentials/pluralization.html
There is a strange behavior with car when the second argument is 0 (count). Plural is used instead of singular.

The default plural rule with the first ternary operation is bugged if we provide 0 !

function pluralDefault(choice, choicesLength) {
    choice = Math.abs(choice);
    if (choicesLength === 2) {
        // prettier-ignore
        return choice
            ? choice > 1
                ? 1
                : 0
            : 1;
    }
    return choice ? Math.min(choice, 2) : 0;
}

Expected behavior

For count from 0 to 1, singular must be used ?

Reproduction

Here a sample of the issue : https://stackblitz.com/edit/vitejs-vite-vow5pz?file=src%2FApp.vue

System Info

WSL / Ubuntu / "vue-i18n": "^9.2.2"

Screenshot

No response

Additional context

No response

Validations

@H3llK33p3r H3llK33p3r added the Status: Review Needed Request for review comments label Oct 2, 2024
@BobbieGoede
Copy link
Member

This looks like it is working as intended to me, only 1 can be singular, anything more or less is not singular.

Your example actually demonstrates this well

  • zero cars (or) no cars
  • zero apples (or) no apples

Using singular for zero amounts would be grammatically incorrect, this probably differs across languages.

@H3llK33p3r
Copy link
Author

Using singular for zero amounts would be grammatically incorrect, this probably differs across languages.

Ok I understand, both can be used depending on the context. It's strange, as a French, to see plural with a 0 quantity !
Thank you for your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Review Needed Request for review comments
Projects
None yet
Development

No branches or pull requests

2 participants