i18next: Languages with multiple plurals not working

https://www.i18next.com/translation-function/plurals

Hi I am using the below keys in my local file as given in the docs https://www.i18next.com/translation-function/plurals

{
     "key": "none",
     "key_0": "zero",
      "key_1": "singular",
      "key_2": "two",
      "key_3": "few",
      "key_4": "many",
      "key_5": "other"
}

However

i18next.t('key', {count: 0}); // -> "none"

Be it any value of count, I always get none And if i remove "key": "none", from the file then I get the error i18next::translator: missingKey

Is there anything I am missing ?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 30 (15 by maintainers)

Most upvoted comments

@jamuhl got it. Thanks a lot for the quick reply. I got confused a bit with the docs . May be if a line is added This is supported only in arabic then that might help.

Maybe documentation isn’t clear enough?

If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.

If you liked my support / work - I would enjoy a coffee sponsored using the “💜Sponsor Button”.

There are many ways to help this project 🙏

Ok, I got it, but in Romanian it only needs the 3rd form if you include the count number too, otherwise it is just as in English (singular or plural).I guess there is no easy way to define the plural if you know you will never add the count. In my case I will just duplicate word_0 and word_2.Thanks for the help!On 14 Feb 2020 07:06, Jan Mühlemann notifications@github.com wrote:@Cristy94 because plural forms and languages in general are more complex than you think I guess. Not every language knows just singular and plural - simple as that. https://lingohub.com/blog/2019/02/pluralization/ but I can understand - it feels confusing when starting…

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.

@jamuhl well turns out i didn’t understood how prefixes work. I thought “_1” prefix means “if count == 1, use _1 prefix”. I don’t know why this misunderstanding happened. I had a brain fart.

image

from documentation: Sample uses arabic which has 5 plural forms beside the singular.

simplifyPluralSuffix will use ‘plural’ as suffix for languages only having 1 plural form, setting it to false will suffix all with numbers

Using: using simplifyPluralSuffix = false key_0: ‘zero ({{count}})’, key_1: ‘singular ({{count}})’, key_2: ‘two ({{count}})’, key_3: ‘few ({{count}})’, key_4: ‘many ({{count}})’, key_5: ‘other ({{count}})’,

receiving:

  • singular (0)
  • zero(1)
  • singular(2)
  • singular(50)
  • singular(100)

How then I handled it? (pt)

  • friend_zero: ‘Nenhum amigo(a)’,
  • friend_zero_plural: ‘Nenhum amigos(as)’,
  • friend_male_zero: ‘Nenhum amigo’,
  • friend_male_zero_plural: ‘Nao ha amigos’,
  • friend_female_zero: ‘Nenhuma amiga’,
  • friend_female_zero_plural: ‘Nao ha amigas’,
  • friend: ‘Um amigo(a) ({{count}})’,
  • friend_plural: ‘Uns amigos(as) ({{count}})’,
  • friend_male: ‘Um amigo ({{count}})’,
  • friend_female: ‘Uma amiga ({{count}})’,
  • friend_male_plural: ‘{{count}} amigos’,
  • friend_female_plural: ‘{{count}} amigas’,
  • neutral: ‘neutro’,
  • female: ‘feminino’,
  • male: ‘masculino’,

How then I handled it? (en)

  • friend_zero: ‘None friend’,
  • friend_zero_plural: ‘No friends’,
  • friend_male_zero: ‘None boyfriend’,
  • friend_male_zero_plural: ‘No boyfriends’,
  • friend_female_zero: ‘None girlfriend’,
  • friend_female_zero_plural: ‘No girlfriends’,
  • friend: ‘A friend ({{count}})’,
  • friend_plural: ‘{{count}} friends ({{count}})’,
  • friend_male: ‘A boyfriend ({{count}})’,
  • friend_female: ‘A girlfriend ({{count}})’,
  • friend_male_plural: ‘{{count}} boyfriends’,
  • friend_female_plural: ‘{{count}} girlfriends’,
  • neutral: ‘neutral’,
  • female: ‘female’,
  • male: ‘male’,
//using key "friend"
//play with context, return 'zero' when 
var _gender_options = ['neutral', 'male', 'female']
var _count = 0
var _gender = _gender_options [0]

/**
is count !==0 then context: _gender
is count === 0 and gender === 'neutral' then context: 'zero'
is count === 0 and gender !== 'neutral' then context:  _gender + '_zero'
*/

i18n.t("friend",
            options={{
              context:
                _count  !== 0
                  ? _gender 
                  : _gender === 'neutral'
                  ? 'zero'
                  : _gender + '_zero',
              count: _count ,
            }}

Not sure what’s is wrong (api? or documentation?) Maybe because “plural” means more than one, but as developer make sense pass the count and leave the strings to translators

@jamuhl the library is awesome !!. I have been using it in my projects. Will check https://locize.com as well.

the above sample is for Arabic - it even says so in the docs…