I've come across different syntax in various pieces of code, mostly only seen when using Django, not Python itself.
For example, when adding a verbose_name
to a field in Django, they do it as follows:
title = models.CharField(_('Titulo'), max_length = 200)
With that strange syntax of _('')
, they also use it when putting a verbose_name
and a verbose_name_plural
to a model, as follows:
class Meta:
verbose_name = _('app')
verbose_name_plural = _('apps')
They could have done it as follows:
class Meta:
verbose_name = 'app'
verbose_name_plural = 'apps'
But they didn't do it, so why with that syntax? Is it advantageous to do it that way? Why do they only use it when working with Django and not in Python as such?
It is a doubt that I have always had, but I have never found information about it. Thanks in advance for your answers!
It appears to be
_()
a global alias that is used togettext()
Read the second Note of the Standard Translation section of this link: