为什么makemessages功能的Django语言本地化忽略html文件? [英] Why would the makemessages function for Django language localization ignore html files?

查看:250
本文介绍了为什么makemessages功能的Django语言本地化忽略html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在项目中运行Django语言本地化,但是makemessages总是忽略我的templates文件夹中的html模板。

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

我正在从项目根目录运行 python manage.py makemessages -a 以及所有字符串被标记为在.pro文件内的.py文件被成功添加到.po文件。

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.

html模板中的任何字符串,即 {{transString_to_translate}} 被忽略,不会添加到.po文件,即使必要的模块加载在模板的顶部, {%加载i18n%}

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

为了测试整个模板文件夹被从makemessages函数中排除的可能性,我创建了一个.py文件包含一个字符串进行翻译,并将其成功添加到.po文件中。

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!

编辑:解决方案仅包含更改 {{transstring}}的语法 {%transstring%}

Solution comprised solely of changing the syntax of {{ trans "string" }} to {% trans "string" %}

推荐答案

您的模板文件夹需要在 INSTALLED_APPS 或目录中列出的应用程序中已在 settings.py 文件中的 TEMPLATE_DIRS 中列出

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

这篇关于为什么makemessages功能的Django语言本地化忽略html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆