cibernox / cibernox/precompile-intl-runtime

Plural "other" does not work as expected in some locales -- it is sometimes "few"

Open
#44 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11
Forks
17
PR merge metrics
No merged PRs in 30d

Description

I'm not sure this is a bug or a feature.

### The problem

I have the following English and Polish pluralized strings (using svelte-intl-precompile to transform them):
- en: `"{numYears, plural, one {1 year or less} other {# years}}"`
- pl: `"{numYears, plural, one {1 rok lub mniej} other {# lat}}"`

They both compile to the same JS options, e.g. for Polish:
```
{
o: "1 rok lub mniej",
h: `${numYears} lat`
}
```

However, numbers like 2, 3 and 4 will print the empty string for Polish but not for English, Danish or German.

### Debugging the problem

After some head-scratching, I found that the problem is due to different Intl Plural rules for Polish that evaluate 2-4 to "few" instead of "other" and thus the "other" clause is not used here:
https://github.com/cibernox/precompile-intl-runtime/blob/83c7d0e8cc68be5276223b089023b8a37e15344c/src/index.ts#L58

### What did I expect

I expected I could use the same translation strings for different locales -- not that I would have to take pluralization rules into account.

### Is there a workaround

Yes, specifically for e.g. Polish, I can add a "few" clause which is identical to the "other" clause: `"{numYears, plural, one {1 rok lub mniej} few {# lat} other {# lat}}"`

Thanks for a great project.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.