intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.21k stars 337 forks source link

Plural behavior with count == 0 #1982

Closed H3llK33p3r closed 1 month ago

H3llK33p3r commented 1 month ago

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

BobbieGoede commented 1 month ago

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

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

H3llK33p3r commented 1 month ago

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.