Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#13317 closed (fixed)

{% blocktrans %}: accessing attributes and general documentation concerning variables

Reported by: Chris Morgan Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords: blocktrans variables attributes
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the Django template system, it's documented about using {% blocktrans %} with local variables; it says that:

"To translate a template expression -- say, using template filters -- you need to bind the expression to a local variable for use within the translation block:"

This caused me quite a bit of trouble as it didn't occur to me for a very long time that accessing attributes on a model object would qualify as a template expression. This meant that for ages I was trying to work out why this caused a KeyError:

{% blocktrans %}That will cost ${{ i.price }}{% endblocktrans %}

I think that it needs to be either specified in docs/topics/i18n/internationalization that this sort of a situation would need to be done like this:

{% blocktrans with i.price as price %}That will cost ${{ price }}{% endblocktrans %}

Or, better still, it should be fixed so that it works... but considering how gettext works this probably isn't reasonable. Currently though it only shows examples of filters and that made it so that the reason my code was breaking didn't occur to me.

Also the documentation of the "count" thing is very vague. It took me a while to work out (partly due to the fact that recognition "count" is missing from the Pygments lexer) that it is just using count instead of with or and, like the following. It could be considerably improved by spelling this out in so many words.

{% blocktrans with i.price as price count i.length as years %}That will cost ${{ price }} per year{% plural %}That will cost ${{ price }} per {{ years }} years{% endblocktrans %}

Attachments (2)

13317-r13135.diff (5.1 KB ) - added by Ramiro Morales 14 years ago.
Patch for trunk
13317-1.1.X-r13137.diff (5.0 KB ) - added by Ramiro Morales 14 years ago.
patch for the 1.1.X branch

Download all attachments as: .zip

Change History (7)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

by Ramiro Morales, 14 years ago

Attachment: 13317-r13135.diff added

Patch for trunk

by Ramiro Morales, 14 years ago

Attachment: 13317-1.1.X-r13137.diff added

patch for the 1.1.X branch

comment:2 by Ramiro Morales, 14 years ago

milestone: 1.2

Ive attached patches for trunk and the 1.1.X that address the issues expressed by th OP and long standing pending enhancements to the documentation of the i18n template tags (see http://groups.google.com/group/Django-I18N/browse_frm/thread/bdcdaf433bfcd144 for an example): Contrast the functionality of trans and blocktrans, describe that blocktrans has two roles.

comment:3 by Ramiro Morales, 14 years ago

Has patch: set

comment:4 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

(In [13185]) [1.1.X] Fixed #13317 - Clarified documentation about how the blocktrans and trans template tags work with regard to variables. Thanks for the initial patch, Ramiro Morales.

Backport from trunk, r13184.

comment:5 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

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