Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trishrempel opened this issue May 18, 2023 · 0 comments

Comments

@trishrempel
Copy link
Collaborator

trishrempel commented May 18, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant