unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.33k stars 174 forks source link

Suggestion: Use `PluralRules` instead of `Count` #5369

Open younies opened 1 month ago

younies commented 1 month ago

Summary

Currently, the enum Count is being used in multiple places around icu4x, such as units, currency, decimal ... etc.

pub enum PluralRulesCount {

  Zero,
  One,
  Two,
... etc.
}
sffc commented 1 month ago

The standard enum already exists: icu_plurals::PluralCategory

I like the idea of component-specific enums extending the standard one. Alternatively, I would be okay with icu_plurals exporting an enum with the explicit rules.

younies commented 4 weeks ago

In this case, we can use icu_plurals::PluralCategory.

But we need to address two things:

  1. When the user extends the enum, there should be a function that handles, let's say, the first 4 bits for verifying and converting from and to the unaligned version of the PluralCategory. Then, the user can manipulate the remaining 4 bits as needed.
  2. Ideally, it would be good if make_ule could handle this without a need of intervetion.
younies commented 4 weeks ago

Example of an extended enume: https://github.com/unicode-org/icu4x/pull/5375

and a problem that need to be solved: https://github.com/unicode-org/icu4x/pull/5375#issuecomment-2291286186

sffc commented 4 weeks ago

Proposal:

LGTM: @sffc @Manishearth @younies @echeran