4

当我在模型的 help_text 上使用 pgettext_lazy 时,我的模板失败了。它适用于 ugettext_lazy。

错误

Caught TypeError while rendering: Lazy object returned unexpected type.

模型

class BalanceIncreaseOrder(models.Model):
    amount = models.FloatField(help_text=pgettext_lazy("Translators: please localize this to reflect the correct currency", "Note: amount will be billed in United States dollars (USD)"))

形式

class BalanceIncreaseOrderForm(ModelFormRequired):
    class Meta:
        model = BalanceIncreaseOrder
        fields = ("amount",)

模板

{% for field in form %}
    {{ field }}
{% endfor %}

在每种方式设置帮助文本之后,我已经调试了模型。两次都打印出来

<django.utils.functional.__proxy__ object at 0x10fcb3a50>

pgettext_lazy 中是否有错误?有任何想法吗?

4

1 回答 1

5

我有同样的问题。我用了

unicode(pgettext_lazy('context', 'string'))

这将消除错误,但现在manage.py makemessages不会选择已翻译的行。

也许这会对你有所帮助..

编辑:

啊,我找到了解决方案:

pgettext_lazy(u'context', u'string')

这将完成这项工作。

于 2012-04-19T09:50:44.220 回答