Opened 3 years ago

Closed 3 years ago

#21417 closed Bug (fixed)

use TEMPLATE_STRING_IF_INVALID format string in blocktrans

Reported by: Kevin Turner Owned by: Claude Paroz <claude@…>
Component: Template system Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ticket:19915 makes it so that TEMPLATE_STRING_IF_INVALID may show when template strings fail inside blocktrans blocks. It doesn't, however, treat that as a format string in the way that FilterExpression.resolve does (as is described in the documentation).

Change History (5)

comment:1 Changed 3 years ago by chrismedrela

Component: UncategorizedTemplate system
Triage Stage: UnreviewedAccepted

To reproduce:

  • set TEMPLATE_STRING_IF_INVALID = "Invalid(%s)"
  • run python manage.py shell and type:
from django.template import Template, Context
t = Template("""{% load i18n %}
    Outside: {{ missing }}
    {% blocktrans %}Inside: {{ missing }}{% endblocktrans %}""")
print(t.render(Context()))
>>>    Outside: Invalid(missing)
>>>    Inside: Invalid(%s)

Missing variables in blocktrans tag are handled here: https://github.com/django/django/blob/326539f6a4936cda031b4a5f7caad788569f3329/django/templatetags/i18n.py#L152. It should work the same like FilterExpression.resolve.

comment:2 Changed 3 years ago by Claude Paroz

Owner: changed from nobody to Claude Paroz
Status: newassigned

comment:3 Changed 3 years ago by Claude Paroz

Has patch: set
Owner: Claude Paroz deleted
Status: assignednew

comment:4 Changed 3 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:5 Changed 3 years ago by Claude Paroz <claude@…>

Owner: set to Claude Paroz <claude@…>
Resolution: fixed
Status: newclosed

In 02add43568b694ef25afeae474b5b1da883826c6:

Fixed #21417 -- Expanded TEMPLATE_STRING_IF_INVALID in blocktrans

Thanks keturn for the reporti, Chris Medrela for details and
Tim Graham for the review.
Refs #19915.

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