Skip to content

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

@dlebech

Description

@dlebech

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:

return key === 'other' ? 'h' : key[0];

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions