Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django translation of model plural when plural form equals singular form

Tags:

django

How can you tell ugettext that the plural form is not the singular form even if they are equal in English?

class News(models.Model):
    class Meta:
        verbose_name = _('news')
        verbose_name_plural = _('news')

makemessages gives this:

#: models.py:134, models.:135
msgid "news"
msgstr "noticia"

Spliting this definition breaks the compilation with "duplicate message definition..."

Workarounds I found:

  • Add a space at the end of the plural form (the one I am using)
  • Write application texts in Esperanto? Just kidding.
like image 336
francescortiz Avatar asked Oct 21 '22 16:10

francescortiz


1 Answers

Try:

from django.utils.translation import pgettext

class News(models.Model):
    class Meta:
        verbose_name = pgettext("news singular", "news")
        verbose_name_plural = pgettext("news plural", "news")
like image 161
Brandon Avatar answered Oct 25 '22 19:10

Brandon