run ./manage.py makemessages -a
find the string in the .po file and translate it like this:
#: templates/test.html:2
#, python-format
msgid "This item is 50% off!"
msgstr "Denne har 50% rabatt!"
run ./manage.py compilemessages
get this error message:
Execution of msgfmt failed: /Users/stiaje/Projects/django-
backend/app/hyre/locale/nb/LC_MESSAGES/django.po:601: format
specifications in 'msgid' and 'msgstr' for argument 1 are not the same
It works if the letter after the percentage is o in all languages, but
fails otherwise.
I tried escaping the percentage symbol as %%, but that resulted in %%
being outputted on runtime.
I tried using \u00e0 instead, but that gave:
Execution of msgfmt failed: /Users/stiaje/Projects/django-
backend/app/hyre/locale/nb/LC_MESSAGES/django.po:980:36: invalid control
sequence
I see that a very similar issue has been reported before, but it is
closed, with a comment saying to open a new issue for followups:
https://code.djangoproject.com/ticket/11240
I can make compilemessages work by manually removing python-format from
the strings with %, but makemessages will just add that back the next time
I run it.
--
Ticket URL: <https://code.djangoproject.com/ticket/33440>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Claude Paroz, Ramiro Morales (added)
* resolution: => invalid
* status: new => closed
* component: Uncategorized => Internationalization
Comment:
#11240 is about a similar issue but with `{% translate %}` template tag.
The main difference is that by design we don't support %-formatting in `{%
translate %}` (see [https://code.djangoproject.com/ticket/11240#comment:16
comment]), which is not the case in `gettext()`. `gettext()` supports
`%-formatting` and `%o` is a valid conversion type (signed octal value) so
there is not much we can do. I'd recommend to remove `50%` from translated
string (it's not something that will change in different languages), e.g.
{{{
gettext('This item is %(discount)s off!') % {'discount': '50%'}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33440#comment:1>