Opened 4 months ago
Last modified 2 weeks ago
#35993 assigned Bug
Replace outdated information on gettext f-string support
Description (last modified by ) ¶
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 , 4 months ago
Description: | modified (diff) |
---|---|
Has patch: | set |
comment:2 by , 4 months ago
Cc: | added |
---|---|
Owner: | set to |
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 3 months ago
Patch needs improvement: | set |
---|
comment:5 by , 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:
- 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).
- 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
- 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 , 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:
- 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
- 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 , 2 weeks ago
Owner: | changed from | to
---|
Assigning to Ahmed Nassar due to the inactivity of the owner.
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!