On Wed, Nov 10, 2010 at 8:26 AM, rmazzocchi
<riccardo.mazzoc...@gmail.com> wrote:
> Hello everyone, I have trouble to solving a problem with
> the internationalization of some strings. To better explane the
> problem I created a simple example:
> The models (models.py) are as follows:
>
> ---------------------------------------------------------------------------
> ------
> #! -*- coding: utf-8 -*-
> from django.db import models
> class Book(models.Model):
>    title = models.CharField(max_length=200)
>    def __unicode__(self):
>        return self.book
>    class Meta:
>        verbose_name_plural="books"
> ---------------------------------------------------------------------------
> -----
>
> In the relative view (views.py) i've imported ugettext
> localization. The intention is to translate the string "test" and
> "Test1" from en to it:
>
> ---------------------------------------------------------------------------
> -----
> #! -*- coding: utf-8 -*-
> from django.http import HttpResponse
> from django.shortcuts import render_to_response
> from django.shortcuts import get_object_or_404
> from django.utils.translation import ugettext as _
> from models import *
> def books(request):
>    book1 = Book.objects.get(pk=1)
>    test = _("hello")
>    test1 = _("hello %(title)s" % {'title':book1.title})

This won't work, the msgid in the gettext catalogue is for "hello
%(title)s", not  the interpolated version. It should be like so:

test1 = _("hello %(title)s") % {'title': book1.title})

So first you get the translated version of the format string, then you
interpolate that with your variables, not the other way around.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to