Coder Social home page Coder Social logo

Comments (6)

mauriziopinotti avatar mauriziopinotti commented on June 7, 2024

Same here, it's a regression in version 3.0.4 (3.0.3 works correctly).

from easy_localization.

mauriziopinotti avatar mauriziopinotti commented on June 7, 2024

@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?

from easy_localization.

flavio-silva avatar flavio-silva commented on June 7, 2024

Same here, I have to downgrade it to 3.0.3

from easy_localization.

dimzeta avatar dimzeta commented on June 7, 2024

Same thing, still present in 3.0.5.

But this is not a bug, this is a feature 🤓

This is present since this PR: #620, which now takes into account pluralization according to language.

final pluralRule = _pluralRule(_locale.languageCode, value);
final pluralCase = pluralRule != null ? pluralRule() : _pluralCaseFallback(value);

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.

from easy_localization.

mauriziopinotti avatar mauriziopinotti commented on June 7, 2024

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: ...
  ));

from easy_localization.

mauriziopinotti avatar mauriziopinotti commented on June 7, 2024

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

  • on easy_localization up to 3.0.6: nobody
  • on easy_localization 3.0.6: 0 members
  • on easy_localization 3.0.7: nobody
  • on easy_localization 3.0.7 with ignorePluralRules: false: 0 members

from easy_localization.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.