【问题标题】:Django Translations compilemessages Error: 'msgstr' is not a valid Python format stringDjango Translations compilemessages 错误:'msgstr' 不是有效的 Python 格式字符串
【发布时间】:2014-06-20 10:00:29
【问题描述】:

由于 % 符号,我有以下错误。知道如何克服这个错误吗?

django-admin.py 编译消息 -l tr

处理 /.../locale/tr/LC_MESSAGES 中的文件 django.po

CommandError:执行 msgfmt 失败:/.../locale/tr/LC_MESSAGES/django.po:139:与“msgid”不同,“msgstr”不是有效的 Python 格式字符串。原因:在指令编号 1 中,字符“{”不是有效的转换说明符。

/.../locale/tr/LC_MESSAGES/django.po:146:与“msgid”不同,“msgstr”不是有效的 Python 格式字符串。原因:在指令编号 1 中,字符“{”不是有效的转换说明符。 msgfmt: 发现 2 个致命错误

models.py

def get_full_title(self):
    return _(u"{discounted_price} TL for {original_price} TL worth of {product_name} at {place_name} {locality} {city} ({discount_percentage}% off)").format(
        discounted_price=int(self.discounted_price),
        original_price=int(self.original_price),
        product_name=self.product.name,
        place_name=self.product.place.name,
        locality=self.product.place.locality,
        city=self.product.place.get_city_display(),
        discount_percentage=self.get_rounded_discount_percentage(),
    )


def get_short_title(self):
    return _(u"{product_name} at {place_name} ({discount_percentage}% off)").format(
        product_name=self.product.name,
        place_name=self.product.place.name,
        discount_percentage=self.get_rounded_discount_percentage(),
    )

django.po

#: deals/models.py:169
#, python-format, python-brace-format
msgid ""
"{discounted_price} TL for {original_price} TL worth of {product_name} at "
"{place_name} {locality} {city} ({discount_percentage}% off)"
msgstr ""
"{discounted_price} TL for {original_price} TL worth of {product_name} at "
"{place_name} {locality} {city} (%{discount_percentage} indirim)"

#: deals/models.py:181
#, python-format, python-brace-format
msgid "{product_name} at {place_name} ({discount_percentage}% off)"
msgstr "{product_name} at {place_name} (%{discount_percentage} indirim)"

【问题讨论】:

    标签: python django translation


    【解决方案1】:

    你可以通过加倍%%来逃避%

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      相关资源
      最近更新 更多