1

I have a model field:

title = models.CharField(pgettext_lazy('context', 'title'), max_length=255)

When I use ugettext_lazy it displays the untranslated string. (in this case 'title')

But with pgettext_lazy it becomes an empty string. (it hides the title label in the admin)

Is this standard behaviour of pgettext? Am I missing something?

.po file contents:

msgctxt "context"
msgid "title"
msgstr ""

admin looks like this http://cl.ly/072o1x3p11161X3x3y2c

Sander van Leeuwen
  • 2,963
  • 2
  • 22
  • 31
  • Do you have something about source string in .po file? Maybe there's a space symbol as a translation or something like that? pgettext seems to be working fine for me – ilvar Feb 21 '12 at 02:50
  • The source in my .po files seem normal. I added it to the question. how did you test it? – Sander van Leeuwen Feb 21 '12 at 08:26

2 Answers2

2

This is the solution:

pgettext_lazy(u'context', u'title')
Sander van Leeuwen
  • 2,963
  • 2
  • 22
  • 31
0

Found it. pgettext_lazy returns a proxy object. Casting to unicode does the trick:

unicode(pgettext_lazy('context', 'title'))

EDIT:

This is not the answer. Because this way manage.py makemessages doesn't pick up the line as 'marked translated'.

Sander van Leeuwen
  • 2,963
  • 2
  • 22
  • 31