Opened 15 years ago

Closed 15 years ago

Last modified 13 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: dev
Severity: Keywords: i18n, blocktrans,
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 15 years ago.
10604-ungettext-additional-vars-name-warning.diff (4.0 KB ) - added by Ramiro Morales 15 years ago.
Documentation patch for this ticket
10604-ungettext-additional-vars-name-warning.2.diff (4.0 KB ) - added by Ramiro Morales 15 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 by Martin Mahner, 15 years ago

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.

by Martin Mahner, 15 years ago

Attachment: ticket-10604-1.diff added

comment:2 by Martin Mahner, 15 years ago

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 by Ramiro Morales, 15 years ago

I think this is a duplicate of #10533.

comment:4 by Malcolm Tredinnick, 15 years ago

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 by Jacob, 15 years ago

Owner: changed from nobody to Jacob
Status: newassigned

by Ramiro Morales, 15 years ago

Documentation patch for this ticket

comment:6 by Ramiro Morales, 15 years ago

Patch needs improvement: unset

by Ramiro Morales, 15 years ago

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

comment:7 by Russell Keith-Magee, 15 years ago

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 by Russell Keith-Magee, 15 years ago

(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 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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