Opened 16 years ago
Closed 16 years ago
#13056 closed (invalid)
erorr in code snippet in documentation
| Reported by: | daniel | Owned by: | nobody |
|---|---|---|---|
| Component: | Documentation | Version: | |
| Severity: | Keywords: | internationalization localization | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In the "Internationalization and localization" documentation page (all versions) it says:
{% blocktrans with book|title as book_t and author|title as author_t %}
This is {{ book_t }} by {{ author_t }}
{% endblocktrans %}
This does not work as "title" is interpreted as filter. I guess this should be "book.title".
Note:
See TracTickets
for help on using tickets.
What do you mean with does not work?. I can use that without problems:
$ PYTHONPATH=~/django/trunk/ ./manage.py shell In [1]: from django.template import Template, Context In [2]: from django.utils.translation import activate In [3]: from django.conf import settings In [4]: settings.USE_I18N Out[4]: True In [5]: Template('{% load i18n %}{% blocktrans with book|title as book_t and author|title as author_t %}This is {{ book_t }} by {{ author_t }}{% endblocktrans %}').render(Context({'book': 'contact', 'author': 'carl sagan'})) Out[5]: u'This is Contact by Carl Sagan' In [6]: activate('es-ar') In [7]: Template('{% load i18n %}{% blocktrans with book|title as book_t and author|title as author_t %}This is {{ book_t }} by {{ author_t }}{% endblocktrans %}').render(Context({'book': 'contact', 'author': 'carl sagan'})) Out[7]: u'Este es Contact por Carl Sagan'It is using the
titlefilter on purpose. You need to read that example in the context of the two examples before it, together they progress from the need to useblocktrans(to intermix fixed text with variable text) to the possibility to assign the result of expression (including filter chaining to local variables inside theblocktransblock and finally to the fact that you can use more than one of these expression -> vars bindings.