【问题标题】:Django ugettext_lazy with concatenated strings带有连接字符串的 Django ugettext_lazy
【发布时间】:2015-04-15 12:01:11
【问题描述】:

在发布此问题之前,我已经搜索了答案。 有一堆长字符串按如下方式拆分,需要翻译

string = "This is a very long " \
          "string to be translated"

标记后

string = _("This is a very long " \
          "string to be translated")

生成的 .po 文件仅保留字符串的第一部分

msgid "This is a very long "
msgstr ""

那么,有什么办法可以让这个工作,最好不要把代码弄乱...

谢谢

【问题讨论】:

  • 我尝试了三引号,它有效,但问题是字符串不能包含 \r\n 字符(使用三引号添加)...

标签: python django string concatenation


【解决方案1】:

根据makemessages 文档,创建消息时,请使用--no-wrap 选项。

我的模特

class Test(models.Model):
    test = models.CharField(
        max_length=20,
        null=True,
        blank=True,
        verbose_name=_(
            'This is a super long description that should never really exist '
            'but it does. Should not wrap.'
        )
    )

./manage.py makemessages --locale=de --no-wrap

没有--no-wrap,它看起来像这样:

#: test/models.py:16
msgid ""
"This is a super long description that should never really exist but it does. "
"Should not wrap."
msgstr ""

添加--no-wrap 后如下所示:

#: test/models.py:16
msgid "This is a super long description that should never really exist but it does. Should not wrap."
msgstr ""

【讨论】:

  • 其实我的问题是我什至没有让第一个案例工作。只提取第一行。
猜你喜欢
  • 2014-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-16
  • 2010-12-30
  • 2020-06-04
  • 1970-01-01
相关资源
最近更新 更多