tornado 国际化

系统环境  :ubuntu 

第一步:创建目录 :

ubuntu@yee:~/notewo/locale/zh_CN/LC_MESSAGES

 

第二步:生成po文件 :

ubuntu@yee:~/notewo$ xgettext L python -k=_ -o notewo.po $(find . -name \.py) $(find templates/ -name \.html) -from-code=UTF-8

翻译 :

ubuntu@yee:~/notewo/$ mv notewo.po  locale/zh_CN/LC_MESSAGES
ubuntu@yee:~/notewo/locale/zh_CN/LC_MESSAGES$ vim notewo.po
将下面这一行:
"Content-Type: text/plain; charset=CHARSET\n"
改为:
"Content-Type: text/plain; charset=UTF-8\n"

#: templates/base.html:17
msgid "Sign out"
msgstr "退出"

其它翻译按照同样的格式进行

 

第三步:

ubuntu@yee:~/notewo/locale/zh_CN/LC_MESSAGES$msgfmt notewo.po -o notewo.mo

 

然后在启动server的时候 :

vim server.py:

from config import config
def
main(): tornado.locale.load_gettext_translations(config['I18N_PATH'], "notewo") tornado.locale.set_default_locale(config['default_locale']) ……………………………… if _name_ == "_main_": main()
vim config.py

config = { 'port': 8888, 'I18N_PATH':os.path.join(os.path.dirname(_file_), "locale"), 'default_locale':'zh_CN', }

在模板中像下面这样的方法使用:

            <div id="nav">
                <a href="/auth/logout">{{ _("Sign out") }}</a>
            </div>

 

大致上就是这样子了

posted @ 2012-11-10 15:15  notewo  阅读(701)  评论(1编辑  收藏  举报