5 ms·
The article covers this, I recommend giving it a more careful read. Let's say you went this route. You've covered English and a handful of other languages (whic
by exogen 8y ago
The article covers this, I recommend giving it a more careful read. Let's say you went this route. You've covered English and a handful of other languages (which have a special pluralization rule for 1, then everything else). So two numbers in the string, four branches. That's not so bad eh?
Now add branches for Brazilian Portuguese and Lingala, which has different strings for 0 or 1, not just 1.
Now add branches for Latvian and Latgalian, which use different strings when the number ends in 0, and still more different strings when the number ends in 1, except for 11.
Now add branches for Slovak and Czech, which don't just have different strings for 1, but additional strings for 2–4.
Now add branches for Irish Gaelic, which has different strings for 1, more for 2, yet more for 3–6, and again different strings for 7–10.
Now add branches for Arabic, which has different strings for 0, more strings for 1, other strings for 2, more strings for numbers ending with 03-10, additional strings for numbers ending with 00-02, excluding 0-2, and then everything else.
That's not even all of them. Who's peeing the bed now?
If you take the branch approach, you'll have hundreds of cases hardcoded into your source code for the languages you want to support. If instead the branches are in your i18n message syntax, each localized message can contain only the branches needed by that language, and your source code doesn't change at all – it just provides the numeric arguments to the i18n message itself to decide what to do with.
In addition to the system described in the article, ICU message syntax is a common choice. Some examples are here: https://formatjs.io/guides/message-syntax/#plural-format https://formatjs.io/guides/message-syntax/#plural-format
Here's a good reference for what pluralization rules are out there in the world: https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#Plural_rule_2_(2_forms) https://developer.mozilla.org/en-US/docs/Mozilla/Localizatio...
- deleted 8y ago[deleted]