I18next: Unexpected property behavior of simplifyPluralSuffix after set false

Created on 5 Jul 2018  路  4Comments  路  Source: i18next/i18next

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.

issue

Most helpful comment

No need to wait...done already in v11.3.4

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

salvador-dali picture salvador-dali  路  7Comments

mblanchette picture mblanchette  路  7Comments

slim-hmidi picture slim-hmidi  路  9Comments

chiouchu picture chiouchu  路  4Comments

AtheistP3ace picture AtheistP3ace  路  5Comments