Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding missing translations in django `.po` files

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

like image 234
FSp Avatar asked Oct 28 '15 09:10

FSp


Video Answer


3 Answers

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.
like image 168
Art Avatar answered Sep 30 '22 04:09

Art


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.

like image 36
Yoan Tournade Avatar answered Sep 30 '22 06:09

Yoan Tournade


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

like image 28
Wouter van Vliet Avatar answered Sep 30 '22 06:09

Wouter van Vliet