Django

Code

Ticket #10604 (closed: fixed)

Opened 1 year ago

Last modified 9 months ago

Document that blocktrans fails if a defined expression is not used

Reported by: bartTC Assigned to: jacob
Milestone: 1.1 Component: Documentation
Version: SVN Keywords: i18n, blocktrans,
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

ticket-10604-1.diff (0.7 kB) - added by bartTC on 03/24/09 07:41:17.
10604-ungettext-additional-vars-name-warning.diff (4.0 kB) - added by ramiro on 06/24/09 18:39:42.
Documentation patch for this ticket
10604-ungettext-additional-vars-name-warning.2.diff (4.0 kB) - added by ramiro on 06/24/09 18:48:07.
Smae patch with a code example fix. Thanks Alex Gaynor for noting it.

Change History

03/24/09 07:40:57 changed by bartTC

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

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.

03/24/09 07:41:17 changed by bartTC

  • attachment ticket-10604-1.diff added.

03/24/09 09:44:47 changed by bartTC

  • needs_better_patch set to 1.

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.

03/24/09 14:31:30 changed by ramiro

I think this is a duplicate of #10533.

03/24/09 18:22:38 changed by mtredinnick

  • stage changed from Unreviewed to Accepted.
  • component changed from Template system to Documentation.
  • summary changed from blocktrans fails if a defined expression is not used to Document that blocktrans fails if a defined expression is not used.
  • version set to SVN.
  • milestone set to 1.1.

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.

04/02/09 13:43:13 changed by jacob

  • owner changed from nobody to jacob.
  • status changed from new to assigned.

06/24/09 18:39:42 changed by ramiro

  • attachment 10604-ungettext-additional-vars-name-warning.diff added.

Documentation patch for this ticket

06/24/09 18:40:30 changed by ramiro

  • needs_better_patch deleted.

06/24/09 18:48:07 changed by ramiro

  • attachment 10604-ungettext-additional-vars-name-warning.2.diff added.

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

07/03/09 00:42:10 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

(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.

07/03/09 01:15:49 changed by russellm

(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.


Add/Change #10604 (Document that blocktrans fails if a defined expression is not used)




Change Properties
Action