Django型与i18n

Django型与i18n,django,forms,internationalization,Django,Forms,Internationalization,我想用不同的语言显示表单:我使用label参数设置参数,并在标签上使用ugettext() agreed_tos = forms.BooleanField(label=ugettext('I agree to the terms of service and to the privacy policy.')) 但是当我在模板中呈现表单时,使用 {{form.as_p}} 标签没有翻译。有人能解决这个问题吗 您应该使用: 模型和表单属性在Django应用程序启动时初始化。如果使用ugettex

我想用不同的语言显示表单:我使用label参数设置参数,并在标签上使用ugettext()

agreed_tos = forms.BooleanField(label=ugettext('I agree to the terms of service and to the privacy policy.'))
但是当我在模板中呈现表单时,使用

{{form.as_p}}
标签没有翻译。有人能解决这个问题吗

您应该使用:


模型和表单属性在Django应用程序启动时初始化。如果使用
ugettext()
ugettext_lazy()
通过在访问字符串值时而不是调用函数时转换字符串来解决此问题。

显然,重要的一点是ugettext_lazy具有登录用户/会话的上下文。
from django.utils.translation import ugettext_lazy

# ... 
  agreed_tos = forms.BooleanField(label=ugettext_lazy('I agree to the terms of service and to the privacy policy.'))