I am trying to run the Django language localization on a project, but makemessages always ignores the html templates in my templates folder.
I'm 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? Thanks in advance for your help!
EDIT: Solution comprised solely of changing the syntax of {{ trans "string" }}
to {% trans "string" %}
Django then provides utilities to extract the translation strings into a message file. This file is a convenient way for translators to provide the equivalent of the translation strings in the target language. Once the translators have filled in the message file, it must be compiled.
This header is sent by your browser and tells the server which language(s) you prefer, in order by priority. Django tries each language in the header until it finds one with available translations. Failing that, it uses the global LANGUAGE_CODE setting.
utils. translation. ugettext_lazy() to translate strings lazily – when the value is accessed rather than when the ugettext_lazy() function is called. In this example, ugettext_lazy() stores a lazy reference to the string – not the actual translation.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With