2012年7月8日 星期日

Python透過gettext實作i18n範例


 1. install gettext

sudo apt-get install gettext
2. write a python code named "gettext.py"
#!/usr/bin/python
# -*- coding: utf-8 -*-
from gettext import gettext as _
print _('Hello!')

3. get .pot file from .py file
pygettext -o gettext.pot gettext.py
4. cp gettext.pot to gettext.po
5. nano gettext.po
change "Content-Type: text/plain; charset=CHARSET\n"
to "Content-Type: text/plain; charset=utf-8\n"
change "Content-Transfer-Encoding: ENCODING\n"
to "Content-Transfer-Encoding: utf-8\n"
msgid "Hello!"
msgstr "哈羅!"

6. msgfmt -o gettext.mo gettext.po
7. mkdir zh_TW.big5/LC_MESSAGES
8. mv gettext.mo zh_TW.big5/LC_MESSAGES/
9. python getteext.py


相關文章 :

Related Posts with Thumbnails
by TemplatesForYou-TFY
SoSuechtig