Search code examples
djangogettextpo

Django - gettext - Strange msgstr ""


I am having problems in translating a string.

Here is my view code:

advice= _("Password must contain at least 1 number or special character")
sentence= advice + " ("+ special_characters + ")"
response_array.append(sentence)

But when I build the po file with django-admin.py makemessages --all, I get a strange .po file:

#: .\mainsite\views.py:131
msgid "Password must contain at least 1 number or special character"
msgstr ""
"Le mot de passe doit contenir au moins 1 chiffre ou un caractère spécial"

I don't succeed in figuring out what is going on. I was waiting for something like:

#: .\mainsite\views.py:131
msgid "Password must contain at least 1 number or special character"
msgstr "Le mot de passe doit contenir au moins 1 chiffre ou un caractère spécial"

Solution

  • This is the normal behaviour for long message strings. During generation of the .po file it gets automatically formatted and long strings will be divided into several lines.

    From the djangobook:

    Long messages are a special case. There, the first string directly after the msgstr (or msgid) is an empty string. Then the content itself will be written over the next few lines as one string per line. Those strings are directly concatenated. Don’t forget trailing spaces within the strings; otherwise, they’ll be tacked together without whitespace!

    Read more here: http://www.djangobook.com/en/2.0/chapter19.html