6

Working with Django, you can use django.utils.translation.ugettext and ....ugettext_lazy (as well as some template tags) to handle translation of localized messages.

Later, with command: django-admin.py makemessages -l <LANGUAGE> you can generate the po file containing the original string, so that the developer can specify the desired translation.

Question: is there a django command, or any other quick way, to find out which messages have not been translated?

Usually I look for the string msgstr "" in the po file, but that's inaccurate, since some translations are multiline, like the following:

#file.py:xyz
msgid ""
"Some very long text"
msgstr ""
"The translation of some very long text"

Thus, looking for msgstr "" I get "false positives" (i.e. strings that are actually translated, but whose translation start the next line). With thousand of lines, this quite often.

Any smart suggestion?

Thanks

FSp
  • 1,545
  • 17
  • 37
  • From what I've seen, django seems to put then untranslated to the top (or possibly the bottom can't remember) of the list of translations – Sayse Oct 28 '15 at 09:46
  • No, I don't think so. I find them in the middle of my `po` file :-/ – FSp Oct 28 '15 at 09:50
  • 1
    Hmm, I can't remember then, our translators switched over to using Poedit which kind of negates this entire problem – Sayse Oct 28 '15 at 09:51
  • 2
    Don't know what IDE you are using, but in PyCharm you can search by regex: `""\n\n` this highlights all untranslated entries. – Leistungsabfall Oct 28 '15 at 10:18
  • In PyCharm adding newline field to search can be done with Crtl +Shift + Enter – Viljami Aug 12 '22 at 07:10

3 Answers3

6

Assuming you are using some popular editors:

  • in most editors, simply search msgstr ""\n\n
  • under windows / with notepad, maybe you will need something like msgstr ""\r\n\r\n
  • you could also try some specialized editors, check this
  • ultimatively, you could do the following: sed -i '/msgstr ""/{N;N; s/\n\n/\n# translate me!\n\n/g}' django.po and then search for # translate me! comments in the file.
Art
  • 2,235
  • 18
  • 34
4

You can use

msgfmt --statistics --output=/dev/null locale/django.po

to see how many missing translations there are (if any), and

msgattrib --untranslated locale/fr/LC_MESSAGES/django.po

to list the untranslated messages.

Yoan Tournade
  • 623
  • 10
  • 15
3

The easiest way to check for missing translations, and other errors, would be to use the "msgcmp" utility. It's actually supposed to be used to compare a translations file (.po) against a template (.pot), but it's perfectly happy to compare a .po file against itself:

msgcmp path/to/nl.po path/to/nl.po

will do the trick, and even fail if any translations are marked as fuzzy (unless you specify --use-fuzzy).

Wouter van Vliet
  • 1,484
  • 11
  • 20