unicode-org / icu4x

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

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

Open younies opened 3 months ago

younies commented 3 months 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 3 months 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 3 months 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 3 months 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 3 months ago

Proposal:

LGTM: @sffc @Manishearth @younies @echeran