Why would the makemessages function for Django language localization ignore html files?

Question:

I am trying to run the Django language localization on a project, but makemessages always ignores the html templates in my templates folder.

I am running python manage.py makemessages -a from the project root, and all of the strings that are marked for translation inside .py files anywhere in the project are successfully added to the .po file.

Any of the strings in the html templates, i.e., {{ trans "String_to_translate" }} are ignored and not added to the .po file even though the necessary module is loaded at the top of the template, {% load i18n %}.

To test the possibility that the whole template folder was excluded from the makemessages function, I made a .py file and included a string for translation there, and it was successfully added to the .po file.

With all of that being said, does anyone know what could possibly be causing this problem?

Asked By: dlmccoy

||

Answers:

Your templates folder either needs to be in an app that has been listed in INSTALLED_APPS or in a directory that has been listed in TEMPLATE_DIRS – in your settings.py file

Answered By: Roshan Mathews

Try creating symlink for your templates folder in your app folder. Then call makemessages from your app folder with symlink switch django-admin.py makemessages --all --symlinks

cd /myproject
ln -s /myproject/templates /myproject/myapp/templates    
cd /myproject/myapp
django-admin.py makemessages --all --symlinks

makemessages ignores TEMPLATE_DIRS and INSTALLED_APPS. Templates dir needs to be inside your app folder and makemessages needs to be called from inside your app folder.

Answered By: pista329

Change the syntax of {{ trans "string" }} to {% trans "string" %}.


This answer was posted as an edit to the question Why would the makemessages function for Django language localization ignore html files? by the OP dlmccoy under CC BY-SA 3.0.

Answered By: vvvvv