Example
i18next.init({
simplifyPluralSuffix: false, // <- it's what I needed
resources: {
ru: {
translation: {
egg_0: '{{count}} 褟泄褑芯', // <- singular
egg_1: '{{count}} 褟泄褑邪', // <- plural
egg_2: '{{count}} 褟懈褑', // <- plural
},
},
en: {
translation: {
egg_0: '{{count}} egg', // <- singular
egg_1: '{{count}} eggs', // <- plural
},
},
},
});
For Russia works ok:
i18next.t('egg', { lng: 'ru', count: 0 }); // -> 0 褟懈褑
i18next.t('egg', { lng: 'ru', count: 1 }); // -> 1 褟泄褑芯
i18next.t('egg', { lng: 'ru', count: 3 }); // -> 3 褟泄褑邪
i18next.t('egg', { lng: 'ru', count: 5 }); // -> 5 褟懈褑
For English don't work same:
i18next.t('egg', { lng: 'en', count: 0 }); // -> egg
i18next.t('egg', { lng: 'en', count: 1 }); // -> 1 eggs
i18next.t('egg', { lng: 'en', count: 3 }); // -> egg
i18next.t('egg', { lng: 'en', count: 5 }); // -> egg
But if I define:
i18next.init({
simplifyPluralSuffix: false, // <- it's what I needed
resources: {
...
en: {
translation: {
egg_1: '{{count}} egg', // <- singular (replace 0 to 1)
egg_2: '{{count}} eggs', // <- plural (replace 1 to 2)
},
},
},
});
i18next.t('egg', { lng: 'en', count: 0 }); // -> 0 eggs
i18next.t('egg', { lng: 'en', count: 1 }); // -> 1 egg
i18next.t('egg', { lng: 'en', count: 3 }); // -> 3 eggs
i18next.t('egg', { lng: 'en', count: 5 }); // -> 5 eggs
It's right behavior? I thought 0 for singular form.
Your right...there is an issue:
https://github.com/i18next/i18next/blob/master/src/PluralResolver.js#L147 -> should also check for the this.options.simplifyPluralSuffix
should be:
} else if (/* v3 - gettext index */ this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
Will fix this asap...or if your in the mood feel free to test and provide a PR.
should be fixed in [email protected]
Oops, I did't have time to do PR)
Ok, I will wait.
Thanks!
No need to wait...done already in v11.3.4
Most helpful comment
No need to wait...done already in v11.3.4