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

i18n: Add support for plural forms #2660

Open
naglis opened this issue Nov 15, 2024 · 3 comments
Open

i18n: Add support for plural forms #2660

naglis opened this issue Nov 15, 2024 · 3 comments

Comments

@naglis
Copy link
Contributor

naglis commented Nov 15, 2024

i18next, the library used by Thorium for translations, supports plurals, but it is currently not used in Thorium.

I think it would be nice to display the correctly pluralized strings instead of appending all the possible variations at the end (e.g. 42 match(es)).

IIUC, there are a few strings that would benefit from plurals in Thorium:

I have experimented with adding support for it (i18next JSON v3, v4), it seems to work nicely. Please note that in order for i18next to apply plurals, the number placeholder must be named count.

There are some issues/unanswered questions:

  • Not sure which i18next JSON version to use. I have found v4 plural suffixes a bit easier to understand (here is a JSFiddle which displays the plural suffixes for a given language/i18next JSON version). It might also make sense to bite the bullet and switch to v4 before adding plurals so as not to have to migrate the keys afterwards. I am not sure if there are any issues (unrelated to plurals) from switching from v3 -> v4, though.
  • i18next-json-sync (the CLI tool to extract translatable strings) does not support plural keys (it simply removes them), although there are alternatives, e.g. https://github.com/felixmosh/i18next-locales-sync.
  • How would GitLocalize handle plural translations? Different languages may have different plural forms, so the key suffixes might also differ, e.g. in i18next JSON v4 the en keys would be: foo_one and foo_other, the lt (Lithuanian) keys would be foo_one, foo_few, foo_other. How would GitLocalize handle the foo_few key (what would it display as the "source" value?) when translating en -> lt?
  • IIUC, GitLocalize does not support adding new strings manually, so in order to add missing plural forms, it would have to be done via PR?
  • ...?
@danielweck
Copy link
Member

Note that since i18next version 24 the syntax for plural keys in the JSON format v4 has changed.

See:

The tooling didn't reveal any change in Thorium's existing JSON locales:

Related commit:

4a80487#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519

@naglis
Copy link
Contributor Author

naglis commented Dec 14, 2024

@danielweck, would you be open to a PR that would change the places in the code where strings with possible plurals are used to use the i18next placeholder count that would enable the plural support (essentially naglis@e2551b1 commit)? This way translators that are comfortable with making PRs could add proper plural support in their languages.

IIUC care would needed (if i18next-json-sync is used) when extracting the translatable strings so that the plural forms are not lost, i.e. extra plural keys removed by i18next-json-sync not committed. Also, I am not sure how GitLocalize would handle the extra plural keys (if it ignores them then it is OK, but hopefully it does not crash altogether).

@danielweck
Copy link
Member

the "count" renaming seems safe for GitLocalize as long as no translation is in-progress (limbo state between an accepted merged pull request and a clean original translation synchronized with GitHub)

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