Use ngettext where plurals are shown #1668

Open
nykula wants to merge 2 commits from nykula/pyfedi:ngettext into main
Contributor

The next pybabel extract + pybabel update should let translators into languages with complex plural forms improve the about page and the community side pane, as well a few flash alerts and other places.

The next pybabel extract + pybabel update should let translators into languages with complex plural forms improve the about page and the community side pane, as well a few flash alerts and other places.
Owner

This looks like a fundamental change in how we do translations, with no prior discussion.

Please bring me up to speed.

This looks like a fundamental change in how we do translations, with no prior discussion. Please bring me up to speed.
Author
Contributor

Gettext is a family of functions, of which the two main ones are gettext (often aliased to _) and ngettext. The latter takes an English singular, an English plural, and a count of something, depending on which a plural is selected. Every PO file specifies the formula for selecting a plural depending on the count. During message extraction, source lines marked with ngettext rather than gettext automatically receive [multiple plural form](https://www.gnu.org/software/gettext/manual/html_node/Entries-with-Plural-Forms.html] inputs for each language according to its rules in Poedit, Weblate or another editor. When a plural isn't found, the corresponding English string is shown. This way, the programmer doesn't have to hardcode the pluralization rules for each language or get weirdly-looking combinations like "1 Users".

It's documented in Flask-Babel hello world, so I didn't consider it a fundamental change. However, you're right, I should have brought this up in Zulip or an issue. I'd appreciate if someone with more Python experience then myself reviewed if I connected the plurals correctly.

Gettext is a family of functions, of which the two main ones are gettext (often aliased to `_`) and ngettext. The latter takes an English singular, an English plural, and a count of something, depending on which a plural is selected. Every PO file specifies the formula for selecting a plural depending on the count. During message extraction, source lines marked with ngettext rather than gettext automatically receive [multiple plural form](https://www.gnu.org/software/gettext/manual/html_node/Entries-with-Plural-Forms.html] inputs for each language according to its rules in Poedit, Weblate or another editor. When a plural isn't found, the corresponding English string is shown. This way, the programmer doesn't have to hardcode the pluralization rules for each language or get weirdly-looking combinations like "1 Users". It's documented in [Flask-Babel hello world](https://python-babel.github.io/flask-babel/index.html#using-translations), so I didn't consider it a fundamental change. However, you're right, I should have brought this up in Zulip or an issue. I'd appreciate if someone with more Python experience then myself reviewed if I connected the plurals correctly.
I should be more attentive when picking parts of
the local patches to commit and send.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u ngettext:nykula-ngettext
git switch nykula-ngettext

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff nykula-ngettext
git switch nykula-ngettext
git rebase main
git switch main
git merge --ff-only nykula-ngettext
git switch nykula-ngettext
git rebase main
git switch main
git merge --no-ff nykula-ngettext
git switch main
git merge --squash nykula-ngettext
git switch main
git merge --ff-only nykula-ngettext
git switch main
git merge nykula-ngettext
git push origin main
Sign in to join this conversation.
No description provided.