django makemessages doesn't recognize trans in templates

2,177 views
Skip to first unread message

Jojo

unread,
Aug 17, 2012, 2:15:59 AM8/17/12
to django...@googlegroups.com
Hi, the subject should be a little clear so, this is the project folder structure

project folder
 locale
  en
    LC_MESSAGES
      django.po
  es
    LC_MESSAGES
      django.po
  it
    LC_MESSAGES
      django.po
  project
    __init__.py
    mochileros
    settings.py
    urls.py
    wsgi.py
  application folder
    models.py
    views.py


I have created a locale folder and after I launched the django-admin.py makemessages command as explained in the documentation, but when I open a .po file (the command create the files actually), I can't found the msgid/msgstr relative to the translation instruction in my template files.
This is my base template.

{% load i18n %} 

<!DOCTYPE html>
<html>
...
<div id="MENU">
<a class="MENU" href="{% url views.home %}">{% trans "home" %}</a>
<a class="MENU" href="{% url views.contacts %}">{% trans "contacts" %}</a>
<a class="MENU" href="{% url views.about_us %}">{% trans "about_us" %}</a>
                ...
        </div>


I have added the LocaleMiddleware in the settings file so, do I forgot something?
Any suggestions?


Thank you in advance

Thomas Orozco

unread,
Aug 17, 2012, 7:27:25 AM8/17/12
to django...@googlegroups.com

You gave us the project layout, but where are the templates?

My guess is that Django is basically not picking them templates up, but I might be off.

There are arguments to the makemessages command that can help you indicate the directory you want messages created for. You can also use higher verbosity I think.
I'm sorry I can't name them on the top of my head though.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/QT9zFkTK5zwJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Melvyn Sopacua

unread,
Aug 17, 2012, 2:06:20 PM8/17/12
to django...@googlegroups.com
On 17-8-2012 4:15, Jojo wrote:

> I have created a locale folder and after I launched the django-admin.py
> makemessages command as explained in the documentation, but when I open a
> .po file (the command create the files actually), I can't found
> the msgid/msgstr relative to the translation instruction in my template
> files.

This is one of the limitations of the makemessages command.
I've ironed out a number of them in a 'projectmessages' management command:
http://dpaste.de/QEA9D/

It's a work in progress, but fits my needs for now. YMMV.

--
Melvyn Sopacua

Jojo

unread,
Aug 17, 2012, 8:06:49 PM8/17/12
to django...@googlegroups.com
i'm sorry, templates are in application folder in the templates directory

Jojo

unread,
Aug 17, 2012, 9:06:25 PM8/17/12
to django...@googlegroups.com
I got it.
My templates files have htm extension and makemessages looks for htmL files, so I used -e option specifying htm extension like this:

django-admin.py makemessages -l es -e htm

Now I have msgid/msgstr that I need.

NOW

I compiled the msgstr with the translations an compiled the messages with the command compilemessages, but I can't see the translations in my page.

For example for this link

<a class="MENU" href="{% url views.contacts %}">{% trans "contacts" %}</a>

I have the msgstr="Contactos". I expect to see "Contactos" in the browser, but I still see "contacts". Any suggestion?

Thank you



Il giorno venerdì 17 agosto 2012 04:15:59 UTC+2, Jojo ha scritto:

Jojo

unread,
Aug 17, 2012, 9:10:38 PM8/17/12
to django...@googlegroups.com
Ok guys, I was missing the LOCALE_PATHS in settings.py, now it works properly.


Il giorno venerdì 17 agosto 2012 04:15:59 UTC+2, Jojo ha scritto:

Tomas Neme

unread,
Aug 17, 2012, 9:11:25 PM8/17/12
to django...@googlegroups.com
> For example for this link
>
> <a class="MENU" href="{% url views.contacts %}">{% trans "contacts" %}</a>
>
> I have the msgstr="Contactos". I expect to see "Contactos" in the browser,
> but I still see "contacts". Any suggestion?

1) case-sensitive. Are you sure you haven't translated "Contacts"
instead of "contacts"?
2) fuzzy-mark. I've noticed that if a translation is marked as
"fuzzy", sometimes gettext doesn't use it

--
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

Jojo

unread,
Aug 20, 2012, 5:18:05 PM8/20/12
to django...@googlegroups.com
what is the meaning of the fuzzy mark?

Nick Apostolakis

unread,
Aug 20, 2012, 5:43:20 PM8/20/12
to django...@googlegroups.com
On Mon, Aug 20, 2012 at 8:18 PM, Jojo <matteo.d...@gmail.com> wrote:
what is the meaning of the fuzzy mark?


fuzzy is some kind of auto translated field.
it may be correct or not.
when you are sure that the translation is correct, you remove the fuzzy annotation and then the translation works fine 
--
-----------------------------------------------------------------------
                    Nick Apostolakis
email:nick...@oncrete.gr
Web Site: http://nick.oncrete.gr
-----------------------------------------------------------------------

Jojo

unread,
Aug 24, 2012, 4:46:23 PM8/24/12
to django...@googlegroups.com, nick...@oncrete.gr
thank you guys! very helpful!


Il giorno lunedì 20 agosto 2012 12:43:20 UTC-5, Nick Apostolakis ha scritto:


On Mon, Aug 20, 2012 at 8:18 PM, Jojo <matteo.d...@gmail.com> wrote:
what is the meaning of the fuzzy mark?


fuzzy is some kind of auto translated field.
it may be correct or not.
when you are sure that the translation is correct, you remove the fuzzy annotation and then the translation works fine 
--
-----------------------------------------------------------------------
                    Nick Apostolakis
email:n...@oncrete.gr
Reply all
Reply to author
Forward
0 new messages