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

fix: Fix invalid ngettext usage #9560

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

last-partizan
Copy link

Description

Format should be called after ngettext, not before.

See example: https://docs.djangoproject.com/en/5.1/topics/i18n/translation/#pluralization

Formatting changes is because i don't know how to properly format it with your previous style, and there's no included autoformat/or formatting linter. I just formatted it automatically with ruff-lsp. Feel free to revert fomatting changes to your style or explain me what to do.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please share the output of before and after this change?

@last-partizan
Copy link
Author

That's very good question, because it got me thinking... And turns out, I missed important detail.

In our production code, we override this class with

            extra = ngettext(
                "Try again later in about {wait} second",
                "Try again later in about {wait} seconds",
                wait,
            ).format(wait=wait)

To fix, invalid usage of "second[s]" in languages with three plural forms (like Ukrainian or Russian). I don't see translations for this string in current DRF, and English has only two plural forms, so there would be no changes at all.

Proper way to fix it, would be the same, and i'm pushing updated changes.

Expected changes in Ukrainian, after this change lands, after updating .po with makemessages and after translations added:

-"Спробуйте ще раз через 5 секунди"
+"Спробуйте ще раз через 5 секунд"

Because we have three plural forms:

  • (singular, 1) - "секунда", or in this case "секунду"
  • (plural 2-4) - "секунди"
  • (plural 5-9) - "секунд"

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

Successfully merging this pull request may close these issues.

2 participants