Search code examples
pythonwindowsunicodeinternationalizationgettext

Python gettext: convert Unicode literals into text


I work in Windows. Python 2.7.2 I have a module in which i have to translate a few messages with gettext. So i create UTF-8 no BOM *.po file, make *.mo out of it and use code like this:

 t = gettext.translation('index','./locale',  languages=['ru'])
_= t.ugettext
t.install()

As a result i have something like this:

(u'\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430')

How to covert it into common UTF-8 text?


Solution

  • How to covert it into common UTF-8 text?

    This is the wrong question. :) It is already UTF-8 text... What you are trying to understand is how to display it as alphabetical characters. This should be automatic in anything that uses strings as visual output. The easiest case, the print function (or statement).

    >>> print u'\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430'
    системная ошибка