Reputation: 8477
In some django models I have often seen
myfield = models.CharField(_('myfield'))
class_name = models.CharField(_('Type'), max_length=128)
What exactly is the _ and tuple
for? I never saw any such in the official django tutorial snippets
Upvotes: 2
Views: 238
Reputation: 441
from django.utils.translation import ugettext as _
Yes this library is used to translate all strings on your django project, of course you have to mark those translation strings, take a look at this Django Docs
Upvotes: 1
Reputation: 18972
Then you didn't look at the right spots of the documentation:
Specify a translation string by using the function ugettext(). It’s convention to import this as a shorter alias, _, to save typing.
from django.utils.translation import ugettext as _
def my_view(request):
output = _("Welcome to my site.")
return HttpResponse(output)
Upvotes: 3
Reputation: 7063
Go see at the top of the file, but it's most often this renamed import:
from django.utils.translation import ugettext as _
(and so it's a function call, not a tuple)
Upvotes: 5