#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)
Change History (12)
comment:1 by , 17 years ago
| Has patch: | set |
|---|
by , 17 years ago
| Attachment: | ticket-10604-1.diff added |
|---|
comment:2 by , 17 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:4 by , 17 years ago
| Component: | Template system → Documentation |
|---|---|
| milestone: | → 1.1 |
| Summary: | blocktrans fails if a defined expression is not used → Document that blocktrans fails if a defined expression is not used |
| Triage Stage: | Unreviewed → Accepted |
| 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 , 17 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
by , 16 years ago
| Attachment: | 10604-ungettext-additional-vars-name-warning.diff added |
|---|
Documentation patch for this ticket
comment:6 by , 16 years ago
| Patch needs improvement: | unset |
|---|
by , 16 years ago
| Attachment: | 10604-ungettext-additional-vars-name-warning.2.diff added |
|---|
Smae patch with a code example fix. Thanks Alex Gaynor for noting it.
comment:7 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
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.