I am using python 2.7 and had issue with lines like:
LOG.warning(_("text"))
This won't work as LOG.warning is expecting a string (str) and ugettext_lazy only knows how to render unicode.
Now the solution I found was to force unicode rendering before calling the logger:
text = 'Test trans'
LOG.warning(u"%s" % _(text))
However, I was surprised to noticed that this code also work:
LOG.warning(_(Test trans %(test)s.') % {'test': 1})
LOG.warning(_('Test trans %s.') % 1)
Can somebody explain why?
Does the %
operator calls for unicode rendering before replacing the variable?
Thanks in advance.