easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

Plurals not working as expected

Open MichaelCodesThings opened this issue 3 years ago • 4 comments

Plurals just going to the default "other" value. Here is an example, the translations:

{ "test": { "zero": "zero", "one": "one", "two": "two", "few": "few", "many": "many", "other": "other" }, }

then if I print out the translations to the console like so:

print(plural("test", 0)); print(plural("test", 1)); print(plural("test", 2)); print(plural("test", 3)); print(plural("test", 4));

it returns:

zero one two other other

So it works for "zero", "one", "two" as expected. But then skips "few" and "many" and defaults to "other".

What constitutes "few" and "many"? Am I to take "other" as being used for plurals and ignore "few" and "many"?

There's no errors so I am not sure if this was the intended functionality. Feels wrong to me.

MichaelCodesThings avatar Apr 17 '23 11:04 MichaelCodesThings

Few and many are just used for some locales afik e.g. for pl and ru. Interestingly I run into the issue that zero does not work for me in the locales en and de.

rekire avatar Jun 30 '24 11:06 rekire

indeed, in my case as well. in Arabic mode if more than 2 it's using "others" instead of using "few" and "many" first. issue persist on version 3.0.3 and 3.0.7

SardorbekR avatar Jul 10 '24 07:07 SardorbekR

In my case it happens with the _ar_rule here

For some reason, it works for ZERO, ONE and TWO, but FEW and MANY are skipped and it uses OTHER directly... I think the whole thing needs a rework

Majidbouikken avatar Jul 20 '24 09:07 Majidbouikken

I've had the same problem and did a bit of research in the code. And what I wound out is, by default plural rules are ignored, so FEW and MANY are ignored in favor of OTHER.

Try setting ignorePluralRules to false when setting EasyLocalization up.

  EasyLocalization(
    supportedLocales: const [Locale('en', 'US'))],
    path: 'assets/translations',
    fallbackLocale: const Locale('en', 'US'),
    ignorePluralRules: false, // <-------------------------------------- Add this 
    child: child
  ),

That did it for me.

gkres avatar Aug 01 '24 12:08 gkres