Opened 9 months ago

Closed 5 months ago

Last modified 5 months ago

#35993 closed Bug (fixed)

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: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
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+.

Change History (15)

comment:1 by Athena, 9 months ago

Description: modified (diff)
Has patch: set

comment:2 by Sarah Boyce, 9 months ago

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

comment:3 by Sarah Boyce, 9 months ago

Patch needs improvement: set

comment:4 by Ahmed Nassar, 6 months 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 6 months ago by Ahmed Nassar (previous) (diff)

comment:5 by Ahmed Nassar, 6 months 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, 6 months 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, 6 months ago

Owner: changed from Athena to Ahmed Nassar

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

in reply to:  7 comment:8 by Ahmed Nassar, 5 months ago

Replying to Abigail Afi Gbadago:

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

I'd like to help move this forward. Based on the discoveries about gettext f-string support limitations, would you prefer to continue work on current PR, or create a new PR addressing the findings in the comments?

comment:9 by Ahmed Nassar, 5 months ago

I've submitted a pull request that addresses this ticket: https://github.com/django/django/pull/19348

comment:10 by Ahmed Nassar, 5 months ago

Patch needs improvement: unset

comment:11 by Sarah Boyce, 5 months ago

Patch needs improvement: set

comment:12 by Ahmed Nassar, 5 months ago

Patch needs improvement: unset

comment:13 by Sarah Boyce, 5 months ago

Triage Stage: AcceptedReady for checkin

comment:14 by Sarah Boyce <42296566+sarahboyce@…>, 5 months ago

Resolution: fixed
Status: assignedclosed

In 2c2f0905:

Fixed #35993 -- Documented gettext f-string support limitations.

Thank you to Claude Paroz and Athena Wolfskämpf for the review.

comment:15 by Sarah Boyce <42296566+sarahboyce@…>, 5 months ago

In aa2c7659:

[5.2.x] Fixed #35993 -- Documented gettext f-string support limitations.

Thank you to Claude Paroz and Athena Wolfskämpf for the review.

Backport of 2c2f09055579cc6068cae6c6fd3135011d6df4f1 from main.

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