Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plurals does not support zero e.g. for en #696

Open
rekire opened this issue Jun 30, 2024 · 3 comments
Open

Plurals does not support zero e.g. for en #696

rekire opened this issue Jun 30, 2024 · 3 comments

Comments

@rekire
Copy link

rekire commented Jun 30, 2024

I am aware that there is no official zero case for the English language and that the default other is technically correct, but supporting the zero case would be nice to handle empty states.

As sample you can use the money example from the readme:

{
  "money": {
    "zero": "You not have money",
    "one": "You have {} dollar",
    "many": "You have {} dollars",
    "other": "You have {} dollars"
  }
}

When I use 'money'.plurals(0, args: [0]) I get the unexpected output: 'You have 0 dollars'. Expected would be 'You not have money'.

@petodavid
Copy link

petodavid commented Jul 15, 2024

Did you set ignorePluralRules to false like this? By default the rules are ignored

    return EasyLocalization(
      supportedLocales: supportedLocales,
      fallbackLocale: supportedLocales.first,
      ignorePluralRules: false,
      path: 'lib/localization',
    );

@rekire
Copy link
Author

rekire commented Jul 15, 2024

Interesting... The documentation for that field is this:

  /// Ignore usage of plural strings for languages that do not use plural rules.
  /// @Default value false
  /// Example:
  /// ```
  /// // Default behavior, use "zero" rule for 0 even if the language doesn't
  /// // use it by default (e.g. "en"). If "zero" localization for that string
  /// // doesn't exist, "other" is still used as fallback.
  /// // "nTimes": "{count, plural, =0{never} =1{once} other{{count} times}}"
  /// // Text(AppLocalizations.of(context)!.nTimes(_counter)),
  /// // will print "never, once, 2 times" for ALL languages.
  /// ignorePluralRules: true
  /// // Use "zero" rule for 0 only if the language is set to do so (e.g. for
  /// "lt" but not for "en").
  /// // "nTimes": "{count, plural, =0{never} =1{once} other{{count} times}}"
  /// // Text(AppLocalizations.of(context)!.nTimes(_counter)),
  /// // will print "never, once, 2 times" ONLY for languages with plural rules.
  /// ignorePluralRules: false
  /// ```
  final bool ignorePluralRules;

But the constructor is this:

  EasyLocalization({
//...
    this.ignorePluralRules = true,
//...
  })

That does not make sense. I'll check that later again.

By the way @petodavid do you know if this flag breaks languages with multiple plural forms?

@petodavid
Copy link

petodavid commented Jul 15, 2024

You should expect no braking change in case you handle the rule cases (ZERO, ONE, TWO, FEW, MANY, OTHER), this depends on the language and not all languages are using all theses cases. For example in English we have ONE and OTHER. Here you can find all the rules: Rules.

Rule for English is this:

PluralCase _en_rule() {
  if (_i == 1 && _v == 0) {
    return ONE;
  }
  return OTHER;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants