I suspect the problem is because _("string") returns a byte string, not a Unicode string.
The obvious workaround is the following:
parser = optparse.OptionParser( description=_('automates the dice rolling in the classic game "risk"').decode('utf-8'), usage=_("usage: %prog attacking defending").decode('utf-8'))
But it's not right.
ugettext or install (True) can help.
Python gettext docs give the following examples:
import gettext t = gettext.translation('spam', '/usr/share/locale') _ = t.ugettext
or
import gettext gettext.install('myapplication', '/usr/share/locale', unicode=1)
I am trying to reproduce your problem, and even if I use install(unicode=1) , I return a byte string ( str type).
Either I'm using gettext incorrectly, or I'm missing a character encoding declaration in my .po / .mo file.
I will update when I find out more.
xlt = _('automates the dice rolling in the classic game "risk"') print type(xlt) if isinstance(xlt, str): print 'gettext returned a str (wrong)' print xlt print xlt.decode('utf-8').encode('utf-8') elif isinstance(xlt, unicode): print 'gettext returned a unicode (right)' print xlt.encode('utf-8')
(Another possibility is to use escape codes or Unicode code codes in a .po file, but that doesn't sound like fun.)
(Or you can look at your .po system files to see how they handle non-ASCII characters.)
Mikel
source share