Opened 15 years ago

Closed 15 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".

Change History (1)

comment:1 by Ramiro Morales, 15 years ago

Resolution: invalid
Status: newclosed

What do you mean with does not work?. I can use that without problems:

$ cat locale/es_AR/LC_MESSAGES/django.po

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-03-08 08:40-0300\n"
"PO-Revision-Date: 2010-03-08 08:42-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms:  nplurals=2; plural=(n != 1);\n"

#: templates/a.html:1
#, python-format
msgid "This is %(book_t)s by %(author_t)s"
msgstr "Este es %(book_t)s por %(author_t)s"
$ PYTHONPATH=~/django/trunk/ ./manage.py compilemessages -l es_AR
$ 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 title filter on purpose. You need to read that example in the context of the two examples before it, together they progress from the need to use blocktrans (to intermix fixed text with variable text) to the possibility to assign the result of expression (including filter chaining to local variables inside the blocktrans block and finally to the fact that you can use more than one of these expression -> vars bindings.

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