首页 >后端开发 >Python教程 >python中的国际化使用

python中的国际化使用

巴扎黑
巴扎黑原创
2016-12-09 14:33:591544浏览

# -*- coding: utf-8 -*-
#!/usr/bin/env python
'''
1.run "python pygettext.py", will generate file messages.pot
2.open messages.pot. charset=gb2313; Content-Transfer-Encoding:utf8
3.save messages.pot as lang.po, then change its name to 'messages.po', now we have 'lang.po' and 'messages.po'
4.create path in your python project: ./locale/cn/LC_MESSAGES/ and ./locale/en/LC_MESSAGES/
5.write code as follow
6.change lang.po. add:
    msgid "Hello world"
    msgstr "世界你好"
7.run "python msgfmt.py lang.po", will generate lang.mo. copy it to ./locale/cn/LC_MESSAGES
8.run "python msgfmt.py messages.po", will generate messages.mo. copy it to ./locale/en/LC_MESSAGES, chang its name to lang.mo
'''
import gettext
gettext.install('lang', './locale', unicode=False)
gettext.translation('lang', './locale', languages=['en']).install(True)
#gettext.translation('lang', './locale', languages=['cn']).install(True)
print _("Hello world")

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn