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

对着背影说爱祢 提交于 2019-12-21 04:31:53

问题


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" %}


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7054082/why-would-the-makemessages-function-for-django-language-localization-ignore-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!