blocktrans strangeness

17 views
Skip to first unread message

akaihola

unread,
Jan 3, 2006, 9:48:42 AM1/3/06
to Django I18N
I'm trying to use gettext for app names in the admin interface. I'm
using Flatpages as an example here, and I've translated the msgid
"Flatpages" in my .po file and verified that gettext recognizes it.

In admin's index.html template we have "<h2>{{ app.name }}</h2>".
I'm replacing it with "<h2>{% blocktrans with app.name as n %}{{ n }}{%
endblocktrans %}</h2>"

For some reason, I still see the original app name in the admin
interface.

For debugging, I inserted below <h2>...</h2> the following:
{% trans 'Flatpages' %}
{% blocktrans %}Flatpages{% endblocktrans %}
and they both show my translation.


As a side note, I'd appreciate if a convention for providing verbose
names for apps was defined (maybe in the app's __init.py__?), and if
the admin interface used translations for those verbose names when
available.

akaihola

unread,
Jan 3, 2006, 9:54:35 AM1/3/06
to Django I18N
And yes, I've read the 2005-11-14 discussion about blocktrans, and yes,
I'm using svn trunk as of today.

hugo

unread,
Jan 3, 2006, 12:32:55 PM1/3/06
to Django I18N
>In admin's index.html template we have "<h2>{{ app.name }}</h2>".
>I'm replacing it with "<h2>{% blocktrans with app.name as n %}{{ n }}{%
>endblocktrans %}</h2>"

Huh? That would produce a message ID like this:

"%(n)s"

And so won't translate anything but just put the value of app.name in
there.

bye, Georg

akaihola

unread,
Jan 4, 2006, 8:53:56 AM1/4/06
to Django I18N
So what should I do to have the value of app.name translated?

(Sorry, I must have hugely misunderstood something here.)

akaihola

unread,
Jan 4, 2006, 9:01:57 AM1/4/06
to Django I18N
Ok, I sorted it out. The answer is, of course, as simple as "{% trans
app.name %}".

hugo

unread,
Jan 4, 2006, 10:56:19 AM1/4/06
to Django I18N
>Ok, I sorted it out. The answer is, of course, as simple as "{% trans
>app.name %}".

Yes, that can work. Only problem: you need to have the applcation name
marked up with one of the gettext or trans things in your code, or
make-messages.py will just throw that line out of your .po file on the
next run. A simple way to do that is to just add some gettext calls
with the right strings to a module in your code - that way
make-messages.py will see those calls and throw the strings into the
.po file. Application names aren't taken from some constant string but
from python module names, so that's why you need to provide your own
translation hooks to be able to translate them.

bye, Georg

akaihola

unread,
Jan 4, 2006, 5:01:48 PM1/4/06
to Django I18N
I decided the most logical place to do a gettext_noop() is the
__init__.py of the application.

It would be kind of neat to either have the app module __name__
registered automatically for translation, or to be able to provide a
verbose_name (and verbose_name_plural) for the application and have the
admin app use that instead of the module __name__.

Reply all
Reply to author
Forward
0 new messages