-
Notifications
You must be signed in to change notification settings - Fork 4
Description
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.