Why does pgettext_lazy break my template but ugettext_lazy does not?

django, internationalization, lazy-evaluation, translation

Solution

I had the same problem. I used

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

This will get rid of the error, but now `manage.py makemessages` doesn't pick up the line as translated.

Maybe this will help you though..

EDIT:

Ah, I found a solution:

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

This will do the job.

Problem

When I use pgettext_lazy to on the help_text of my model, my template fails. It works fine with ugettext_lazy. Error ``` Caught TypeError while rendering: Lazy object returned unexpected type. ``` Model ``` 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)")) ``` Form ``` class BalanceIncreaseOrderForm(ModelFormRequired): class Meta: model = BalanceIncreaseOrder fields = ("amount",) ``` Template ``` {% for field in form %} {{ field }} {% endfor %} ``` I've debugged the model just after setting the help text each way. Both times it prints out ``` <django.utils.functional.__proxy__ object at 0x10fcb3a50> ``` Is there a bug in pgettext_lazy? Any ideas?

Original source