#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)
Change History (7)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 15 years ago
Attachment: | 13317-r13135.diff added |
---|
comment:2 by , 15 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 , 15 years ago
Has patch: | set |
---|
comment:4 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch for trunk