【问题标题】:Django translation of model plural when plural form equals singular form当复数形式等于单数形式时模型复数的Django翻译
【发布时间】:2013-02-24 18:16:41
【问题描述】:

你怎么能告诉 ugettext 复数形式不是单数形式,即使它们在英语中是相等的?

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

makemessages 给出了这个:

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

拆分此定义会使用“重复消息定义...”破坏编译

我找到的解决方法:

  • 在复数形式的末尾添加一个空格(我正在使用的那个)
  • 用世界语编写应用程序文本?开个玩笑。

【问题讨论】:

    标签: django


    【解决方案1】:

    试试:

    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")
    

    【讨论】:

    • 这与我所寻找的相反。我希望 verbose_name_plural 有不同的翻译,不一样。
    • 嗯。对不起,我误解了你的问题,我越看它,这是一个很好的问题。我已经为你更新了我的代码示例。
    • 我将您的代码更改为使用 pgettext_plural,但这成功了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多