Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#10604 closed (fixed)

Document that blocktrans fails if a defined expression is not used

Reported by: Martin Mahner Owned by: Jacob
Component: Documentation Version: master
Severity: Keywords: i18n, blocktrans,
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Blocktrans doesn't handle non-used expressions:

{% blocktrans count cl.result_count as total_count and cl.opts.verbose_name as verbose_name and cl.opts.verbose_name_plural as verbose_name_plural %}
0 of {{ total_count }} {{ verbose_name }} selected
{% plural %}
0 of {{ total_count }} {{ verbose_name_plural }} selected
{% endblocktrans %}

The above template raises an Exception with KeyError: u'verbose_name'. If I use verbose_name *and* verbose_name_plural in one group, it works.

Attachments (3)

ticket-10604-1.diff (683 bytes) - added by Martin Mahner 8 years ago.
10604-ungettext-additional-vars-name-warning.diff (4.0 KB) - added by Ramiro Morales 7 years ago.
Documentation patch for this ticket
10604-ungettext-additional-vars-name-warning.2.diff (4.0 KB) - added by Ramiro Morales 7 years ago.
Smae patch with a code example fix. Thanks Alex Gaynor for noting it.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 8 years ago by Martin Mahner

Has patch: set

Here is a less cluttered example:

{% blocktrans count 1 as counter and "singular" as sing and "plural" as plur %}
    {{ sing }}
{% plural %}
    {{ plur }}
{% endblocktrans %}

Problem is, that the result only gets the variables out of the pural block. If you - in the single block - have a variable that is not listet in the plural block, it fails with a KeyError.

The attached patch merges the variables from the singular and the plural block into one. This works for me, tests went fine.

Changed 8 years ago by Martin Mahner

Attachment: ticket-10604-1.diff added

comment:2 Changed 8 years ago by Martin Mahner

Patch needs improvement: set

Seems to be a limitation of gettext itself. Current patch works fine in Django, creates correct msgid's in the .po file but if I want to compile a po snippet like

#: templates/base.html:5
#, python-format
msgid "%(sing)s"
msgid_plural "%(plur)s"
msgstr[0] "translated: %(sing)s"
msgstr[1] "translated: %(plur)s"

it fails with:

LC_MESSAGES/django.po:27: a format specification for argument 'sing', as in 'msgstr[0]', doesn't exist in 'msgid'

I think it's out of Django's scope to fix this. However I leave this ticket open for discussion or references.

comment:3 Changed 8 years ago by Ramiro Morales

I think this is a duplicate of #10533.

comment:4 Changed 8 years ago by Malcolm Tredinnick

Component: Template systemDocumentation
milestone: 1.1
Summary: blocktrans fails if a defined expression is not usedDocument that blocktrans fails if a defined expression is not used
Triage Stage: UnreviewedAccepted
Version: SVN

There's nothing we can do here except document this. Gettext is broken in this respect and we have to live with it. leaving open until we document it.

comment:5 Changed 8 years ago by Jacob

Owner: changed from nobody to Jacob
Status: newassigned

Changed 7 years ago by Ramiro Morales

Documentation patch for this ticket

comment:6 Changed 7 years ago by Ramiro Morales

Patch needs improvement: unset

Changed 7 years ago by Ramiro Morales

Smae patch with a code example fix. Thanks Alex Gaynor for noting it.

comment:7 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [11164]) Fixed #10604 -- Added note on the limitation of ungettext, especially as relating to the {% blocktrans %} tag. Thanks to bartTC for the report, and Ramiro Morales for the patch.

comment:8 Changed 7 years ago by Russell Keith-Magee

(In [11167]) [1.0.X] Fixed #10604 -- Added note on the limitation of ungettext, especially as relating to the {% blocktrans %} tag. Thanks to bartTC for the report, and Ramiro Morales for the patch.

Merge of r11164 from trunk.

comment:9 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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