# -*- 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”)