Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#15157 closed (fixed)

Literals marked up with _() in templates are translated at compilation time, don't change when locale is switched

Reported by: ramiro Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords: activate deactivate template
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This issue had been reported in the -dev mailing list a while back: https://groups.google.com/d/topic/django-developers/rxjxtwEMAEY/discussion

>>> from django.utils.translation import activate, deactivate
>>> from django.template import Template, Context
>>>
>>> activate('de')
>>> t = Template("{{ _('No') }}")
>>> activate('nl')
>>> t.render(Context({}))
>>> 'Nein' # Should be 'Nee'

Proposed fix changes a call from ugettext() to ugettext_lazy() in handling of the '_(', ')' literals during template variables resolution. Tests included also verify trans and blocktrans tags work, just in case.

Attachments (1)

15157.diff (6.1 KB) - added by ramiro 4 years ago.
Proposed fix, includes tests

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by ramiro

Proposed fix, includes tests

comment:1 Changed 4 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Literals marked up with _() intemplates are translated at template compilation time, don't change when locale is switched to Literals marked up with _() in templates are translated at compilation time, don't change when locale is switched

comment:2 Changed 4 years ago by jezdez

  • milestone set to 1.3
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 4 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

(In [15327]) Fixed #15157 -- Modified evaluation of literals surrounded by _(' and ')' in templates to be evaluated at render time instead of at compile time by using ugettext_lazy. Thanks Jonathan S for the report.

comment:4 Changed 4 years ago by ramiro

(In [15328]) [1.2.X] Fixed #15157 -- Modified evaluation of literals surrounded by '_(' and ')' in templates to be done at render time instead of at compile time by using ugettext_lazy. Thanks Jonathan S for the report.

Backport of [15327] from trunk

comment:5 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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