Python gettext:将 Unicode 文字转换为文本

发布于 2024-12-18 13:47:41 字数 401 浏览 4 评论 0原文

我在 Windows 中工作。 Python 2.7.2 我有一个模块,我必须在其中使用 gettext 翻译一些消息。 所以我创建了 UTF-8 no BOM *.po 文件,用它制作 *.mo 并使用如下代码:

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

结果我有这样的东西:

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

如何将其转换为常见的 UTF-8 文本?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救星 2024-12-25 13:47:41

如何转换为普通的UTF-8文本?

这是错误的问题。 :) 它已经是 UTF-8 文本...您想要了解的是如何将其显示为字母字符。对于任何使用字符串作为视觉输出的东西来说,这应该是自动的。最简单的情况是 print 函数(或语句)。

>>> print 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?

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'
системная ошибка
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文