Closed DafiMjd closed 2 months ago
Same here, it's a regression in version 3.0.4 (3.0.3 works correctly).
@aissat any update on this issue? Looks like you made a new release but this fix is not included... it's a major regression so I think it should have priority over new feature, right?
Same here, I have to downgrade it to 3.0.3
Same thing, still present in 3.0.5.
But this is not a bug, this is a feature 🤓
This is present since this PR: https://github.com/aissat/easy_localization/pull/620, which now takes into account pluralization according to language. https://github.com/aissat/easy_localization/blob/63a39744ca18e38e51b5d30dbb63b95925b27ef5/lib/src/localization.dart#L140-L141
Pluralization is now based on the rules in plural_rules.dart
. These rules are written from The Unicode CLDR (Common Locale Data Repository), and only a few languages have a specific rule for zero.
If your selected language does not have a specific rule for zero, it will use the "one" or "other" translation. Example for English:
PluralCase _en_rule() {
if (_i == 0 || _i == 1) {
return ONE;
}
return OTHER;
}
I used to do something like this, which does not work anymore:
{
"zero": "No card",
"one": "1 card",
"other": "{} cards"
}
To fix this, we have to use it like this:
{
"zero": "No card",
"one": "{} card",
"other": "{} cards"
}
As you can see, the bad news here is we can't no longer use "zero", unless the language has a specific rule.
To me, it will be nice to include "zero" to every language, to be able to display a custom translation in this case.
I have sent PR #668 for this: there's a new forcePluralCaseFallback
option that can be set to true
to enable the "legacy" behavior (pre-3.0.4). It defaults to false
though, so that the new behavior is still used by default.
runApp(EasyLocalization(
// ...
forcePluralCaseFallback: true,
child: ...
));
Commenting for clarity: after upgrading to easy_localization 3.0.7 you'll get the "old" behavior by default, with an option (ignorePluralRules
) to switch to the new one.
So, if you have
"label_members": {
"zero": "nobody",
"one": "{} member",
"two": "{} members",
"other": "{} members"
},
then
LocaleKeys.label_members.plural(0)
will give
nobody
0 members
nobody
ignorePluralRules: false
: 0 members
I have this json: "test": { "zero": "0Test", "one": "1Test", "many": "many{digit} Tests", "other": "other{digit} Tests" }
when i use LocaleKeys.test.plural(0) it outputs as other