[Solved]-Translating formatted strings in Django not working

21👍

You should format the strings returned by ugettext and not the strings in the call. See clarification below.

Instead of:

translation.ugettext('foo %s' % 'bax')
translation.ugettext('foo %(baz)s' % {'baz': 'bax'})
translation.ugettext('foo {}'.format('bax'))
translation.ugettext('foo {baz}'.format(baz='bax'))

You need to do:

translation.ugettext('foo %s') % 'bax'
translation.ugettext('foo %(baz)s') % {'baz': 'bax'}
translation.ugettext('foo {}').format('bax')
translation.ugettext('foo {baz}').format(baz='bax')

In your code you are trying to get the translation of 'foo bax' each time, and you don’t have that msgid in your translation file.

Leave a comment