Opened 4 months ago

Last modified 2 weeks ago

#35993 assigned Bug

Replace outdated information on gettext f-string support

Reported by: Athena Owned by: Ahmed Nassar
Component: Documentation Version: 5.1
Severity: Normal Keywords:
Cc: Claude Paroz Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description (last modified by Athena)

gettext 0.23+ supports the f-string syntax according to their bugtracker. Testing in practice confirms this. The current version of the documentation says that the syntax is not supported. The associated Pull Request changes this to inform the reader that they can use f-string syntax with gettext 0.23+.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To improve the patch as described in the pull request review comments or on this ticket, then uncheck "Patch needs improvement".
  • If creating a new pull request, include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (7)

comment:1 by Athena, 4 months ago

Description: modified (diff)
Has patch: set

comment:2 by Sarah Boyce, 4 months ago

Cc: Claude Paroz added
Owner: set to Athena
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:3 by Sarah Boyce, 3 months ago

Patch needs improvement: set

comment:4 by Ahmed Nassar, 3 weeks ago

Hello,
I'd love to contribute to this issue and help improve the patch. Could you provide more details on what specific improvements are needed?
Looking forward to contributing!

Last edited 3 weeks ago by Ahmed Nassar (previous) (diff)

comment:5 by Ahmed Nassar, 3 weeks ago

Hi everyone,

After reviewing the current state of PR #18910 and doing some additional testing regarding gettext f-string support, I'd like to contribute some important findings:

  1. There seems to be a misunderstanding about the actual f-string support in gettext 0.23+. The NEWS entry stating "Python: xgettext now recognizes the f-string syntax" actually indicates that newer versions of xgettext no longer extract f-strings into .po files (contrary to version 0.21.1 which did).
  1. Important technical limitations:
    • F-string expressions are evaluated before Python's gettext implementation can process them
    • Django uses Python's gettext implementation rather than the system gettext
    • This means we cannot use f-strings directly with gettext in the way many might expect
  1. Suggested documentation updates should:
    • Clarify these limitations explicitly
    • Provide correct usage examples
    • Explain why certain patterns don't work (e.g., _(f"Welcome {staff}"))
    • Recommend proper alternatives using .format() or % formatting

I can help update the PR to reflect these findings and provide clearer documentation about what is and isn't supported. Would this approach be helpful?

comment:6 by Ahmed Nassar, 3 weeks ago

Hello,

I've reviewed PR #18910 and identified some critical technical aspects regarding gettext f-string support that need to be addressed in the documentation:

  1. There's a key misunderstanding about gettext 0.23+ behavior:
    • The change actually prevents f-string extraction, rather than adding support
    • This differs from 0.21.1 which extracted f-strings into .po files
  1. Important technical limitations:
    • F-string expressions evaluate before gettext processing occurs
    • Django uses Python's gettext implementation, not system gettext

I'd be happy to help improve the patch by:

  • Adding clear documentation about these limitations
  • Providing correct usage examples
  • Including proper alternatives using .format() or % formatting
  • Explaining why patterns like _(f"Welcome {staff}") don't work

Would this approach align with what's needed for this ticket? I can submit an updated PR addressing these points.

Best regards

comment:7 by Abigail Afi Gbadago, 2 weeks ago

Owner: changed from Athena to Ahmed Nassar

Assigning to Ahmed Nassar due to the inactivity of the owner.

Note: See TracTickets for help on using tickets.
Back to Top