Categories
Python

Why isn’t my translation showing up?

Here we go again for another post of this blog’s irregular column, entitled Django’s Friday Tips. Today let’s address a silent issue, that any of you that have formerly worked with internationalization (i18n) almost certainly already faced.

You add a string that must be translated:

from django.utils.translation import gettext_lazy as _

some_variable = _("A key that needs translation")

You then execute the manage.py makemessages --locale pt command, go to the generated django.po file and edit the translation:

msgid "A key that needs translation"
msgstr "Uma chave que precisa de tradução"

You compile (manage.py compilemessages --locale pt), and proceed with your work.

A few moments later, when checking the results of your hard effort… nothing, the text is showing the key (in English).

Time to double-check the code (did I forgot the gettext stuff?), the translation file, the I18n settings, etc. What the hell?

Don’t waste any more time, most likely the translation is marked as fuzzy, like this:

#: myapp/module.py:3
#, fuzzy
#| msgid "Another key that needed translation"
msgid "A key that needs translation"
msgstr "Uma chave que precisa de tradução"

You see, you didn’t notice that #, fuzzy line and kept it there. The command that compiles those translations ignores the messages marked as fuzzy.

So the solution is to remove those extra 2 lines, or to compile with the --use-fuzzy⁣ flag. That’s it, compile, and you should be able to proceed with the problem solved.

Leave a Reply

Your email address will not be published. Required fields are marked *