Skip to content

Provide simple fallback for pluralization if no implementation exists for Intl.PluralRules #48

@trishrempel

Description

@trishrempel

Currently, if no implementation exists for Intl.PluralRules, this plugin will throw an exception, which will potentially crash the application and display no content.

We could instead potentially fall back to some basic pluralization functionality, which, if potentially incorrect, would be a better end user experience.

Solution proposal

If no implementation exists for Intl.PluralRules:

  • Log an error
  • Implement basic English pluralization rules to select a "preferred" key, and attempt to find a matching key based on that and a list of pluralization keys in order of most common for most locales and use cases to least common.

Sample implementation:

const preferredKey = count === 1 ? 'one' : 'other';
const firstFoundKey = [preferredKey, 'other', 'one', 'few', 'many', 'zero', 'two'].find(key, subKeys.includes?(key));

^ Basically it'll attempt to find the most appropriate subkey according to English rules. Assume subKeys is a list of subkeys you've gotten from the translation file already.

The key order in this list is off-hand; we should consult with localization experts on the ideal order of the array, as to which pluralization subkeys are the "least bad" to have returned if "one" or "other" can't be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions