aissat / easy_localization

Easy and Fast internationalizing your Flutter Apps
https://pub.dev/packages/easy_localization
MIT License
925 stars 336 forks source link

Plurals not working as expected #573

Open MichaelCodesThings opened 1 year ago

MichaelCodesThings commented 1 year ago

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.

rekire commented 4 months ago

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.

SardorbekR commented 4 months ago

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

Majidbouikken commented 4 months ago

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

gkres commented 3 months ago

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.