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})
    return render_to_response('books.html',
{'books':Book.objects.all().order_by('titile'),
                                            'test':test,
                                            'test1':test1})
---------------------------------------------------------------------------
-

The template that prints the results is as follows (templates /
books.html):

---------------------------------------------------------------------------
-
<h1>My library / {{ test }} / {{ test1 }}</h1>
---------------------------------------------------------------------------
---

>From the app directory run the 'Django-admin-l makemessages it'
command and
Library / locale / it / LC_MESSAGES/django.po is created.
Now i've opened the 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 <em...@address>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-11-08 17:42+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <em...@address>\n"
"Language-Team: LANGUAGE <l...@li.org>\n"
"Language: \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"
#: views.py:12
msgid "hello"
msgstr ""
#: views.py:13
#, python-format
msgid "hello %(titolo)s"
msgstr " %(titolo)s"
---------------------------------------------------------------------------
----------------------

Now I've changed this two string to:

---------------------------------------------------------------------------
-------------------------
#: views.py:12
msgid "hello"
msgstr "ciao"
#: views.py:13
#, python-format
msgid "hello %(titolo)s"
msgstr "ciao %(titolo)s"
---------------------------------------------------------------------------
----------------------------

Now launch django-admin compilemessages and
django.mo is successfully created. Unfortunally when I go to test
my application the result is the following

---------------------------------------------------------------------------
----------------------------
My Library / ciao / hello On The Road
---------------------------------------------------------------------------
-----------------------------

So as a result I have the normal string is
correctly translated, while the second string, that contain
parameters, is ignored.
I cant understand where's the mistake!
Thank you!

-- 
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