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

Support pluralization rules for constructed languages (conlangs) #2150

Closed
noomorph opened this issue Feb 26, 2024 · 2 comments
Closed

Support pluralization rules for constructed languages (conlangs) #2150

noomorph opened this issue Feb 26, 2024 · 2 comments

Comments

@noomorph
Copy link

noomorph commented Feb 26, 2024

🚀 Feature Proposal

There has to be an option:

  1. either to pass custom language codes with their pluralization rules, i.e.:
i18next.init({
  // ...
  pluralRules: [
    {
      lngs: ['art-x-interslv'],
      nr: [1,2,5],
      fc(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);},
    },
  ],
});

Note

At the moment, PluralResolver.js looks hardcoded to a set of popular languages, so this option requires some changes in code.

  1. or to parse CLCR convention of art-x-???????? (where ???????? is the language name) in your LanguageUtils.js (getLanguagePartFromCode) and allow adding significant enough constructed languages. For example:
art-x-neolatin → neolatin
art-x-interslv → interslv

Note

Without the respective change, getLanguagePartFromCode will return art (Artificial) which is unusable for this purpose.

Motivation

I want to contribute Interslavic translation to Allure Reporter, and the maintainers are okay about this, but...

The problem is that their project is using i18next, where I cannot configure pluralization rules for Interslavic language:

For reasons of clarity, however, it is recommended to use the nominative singular after 1, the nominative plural after 2-4 and the genitive plural after 5 and more: 1 dom, 2 domy, 3 domy, 4 domy, 5 domov. 12

Although new Intl.PluralRules(...) may never work correctly for some minority languages, I hope that this issue can be mitigated on the compatibility layer level (v1-v3) at the very least.

Example

While the basic functionality of i18next works, this feature would enable translating plurals in unrecognized languages, which is essential to build software supporting these languages and contributing to their development:

Screenshot demonstrates the issue with translation of plurals

Footnotes

  1. https://interslavic.fun/learn/grammar/numerals/#cardinal-numbers

  2. http://steen.free.fr/interslavic/numerals.html

@jamuhl
Copy link
Member

jamuhl commented Feb 26, 2024

i18next.services.pluralResolver.addRule(locale, rule) https://github.com/i18next/i18next/blob/master/src/PluralResolver.js#L107 can be called for v1-v3 to add custom plural rules

@noomorph
Copy link
Author

noomorph commented Feb 26, 2024

Thank you very much! 🙏 I will close the issue for now then. If there are blockers, I'll re-open with new details.

UPD: Yes, it worked perfectly.

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

2 participants