Translation question : some strings not translated

9 views
Skip to first unread message

François Verbeek

unread,
Jul 2, 2009, 3:05:44 PM7/2/09
to django...@googlegroups.com
Hi,

I've been struggling with this for a while now... Calling for help.. I
believe I'm doing something stupid :


here is a view :

def display_vak_teacher(request,**kwargs):
(.... skip skip skip)
slogan=ugettext_lazy("Welcome to the page of the %(subj)s class
of %(fn)s %(ln)s" % {
'subj':vak_per_teacher.vak.name.lower(),
'fn':vak_per_teacher.teacher.first_name,
'ln':vak_per_teacher.teacher.last_name})
return render_to_response(template, {
(some more stuff)
'slogan' : slogan,
(some more stuff again)
})

and a django.po file that looks like (for that string):

#: content/views.py:362
#, python-format
msgid "Welcome to the page of the %(subj)s class of %(fn)s %(ln)s"
msgstr "Welkom op de pagina van de klas %(subj)s van %(fn)s %(ln)s"

It apparently never gets translated. What am I doing wrong?
All strings with no variables included are translated all right, but
all the ones with a variable are not.
I must be missing something very obvious but I can't find what...

any idea?

Francois

François Verbeek

unread,
Jul 2, 2009, 4:31:27 PM7/2/09
to django...@googlegroups.com
Mmm to make the problem easier to deal with I wrote a very very small app with just 1 view and a very basic template :

from django.http import HttpResponse
from django.utils.translation import ugettext as _
from django.shortcuts import render_to_response,get_object_or_404
def display_a_string_through_template(request,**kwargs):
     data=kwargs.get("argument","nothing")
     string=_("Hi, there %(wee)s" % {'wee':data})
     template="renderit.html"
     another_string=_("a second string")
     string2="something"
     context={'string':string,'astring':another_string,'string2':string2}
     return render_to_response(template,context)


template : 

{% load i18n %}
{{string}} <br />
{% trans "Hi, there " %} <br />
{{astring}}<br />
{% blocktrans %}Hi there {{string2}} incl {%endblocktrans%}


 locale/fr/LC_MESSAGES/django.po 

#: content/views.py:7 content/views.py:13
#, python-format
msgid "Hi, there %(wee)s"
msgstr " fr trna %(wee)s"

#: content/views.py:8 content/views.py:15
msgid "a second string"
msgstr " senc str fr"

#: content/templates/renderit.html:4
msgid "Hi, there "
msgstr " sdfs sfdf fr"

#: content/templates/renderit.html:6
#, python-format
msgid "Hi there %(string2)s incl "
msgstr "fr ici %(string2)s bla"



And setting.py has LANGUAGE_CODE = 'fr'.

If I use ugettext or ugettext_lazy, I get always the same thing : the first string _("Hi, there %(wee)s" % {'wee':data}) is never translated.
{% blocktrans %}Hi there {{string2}} incl {%endblocktrans%} on the other hand is translated all right... 


Matthias Kestenholz

unread,
Jul 2, 2009, 4:39:11 PM7/2/09
to django...@googlegroups.com
Hi,

2009/7/2 François Verbeek <fran...@verbeek.name>:


> Mmm to make the problem easier to deal with I wrote a very very small
> app with just 1 view and a very basic template :
> from django.http import HttpResponse
> from django.utils.translation import ugettext as _
> from django.shortcuts import render_to_response,get_object_or_404
> def display_a_string_through_template(request,**kwargs):
>      data=kwargs.get("argument","nothing")
>      string=_("Hi, there %(wee)s" % {'wee':data})

This should be _("Hi, there %(wee)s") % {'wee': data}

Note the placement of parentheses. gettext recognizes only the string
"Hi, there %(wee)s" before interpolation, and not anymore when the
content of 'wee' has been filled in.


Matthias

Gabriel .

unread,
Jul 2, 2009, 4:38:52 PM7/2/09
to django...@googlegroups.com
2009/7/2 François Verbeek <fran...@verbeek.name>:

uest,**kwargs):
>      data=kwargs.get("argument","nothing")
>      string=_("Hi, there %(wee)s" % {'wee':data})
>      template="renderit.html"

Use:

_("Hi, there %(wee)s") % {'wee':data}


--
Kind Regards

François Verbeek

unread,
Jul 2, 2009, 4:42:18 PM7/2/09
to django...@googlegroups.com
That's it! I guess I didn't wonder because I didn't get any error
back, but it makes sense.
Thank you !

François
Reply all
Reply to author
Forward
0 new messages