Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Translations compilemessages Error: 'msgstr' is not a valid Python format string

I have the following error due to % sign. Any idea how to overcome this error?

django-admin.py compilemessages -l tr

processing file django.po in /.../locale/tr/LC_MESSAGES

CommandError: Execution of msgfmt failed: /.../locale/tr/LC_MESSAGES/django.po:139: 'msgstr' is not a valid Python format string, unlike 'msgid'. Reason: In the directive number 1, the character '{' is not a valid conversion specifier.

/.../locale/tr/LC_MESSAGES/django.po:146: 'msgstr' is not a valid Python format string, unlike 'msgid'. Reason: In the directive number 1, the character '{' is not a valid conversion specifier. msgfmt: found 2 fatal errors

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)"
like image 704
Dogukan Tufekci Avatar asked Dec 14 '22 23:12

Dogukan Tufekci


1 Answers

You can the escape the % by doubling it up %%

like image 57
cchristelis Avatar answered May 07 '23 11:05

cchristelis