Skip to main content
 首页 » 编程设计

python之i18n 与 webpy

2025年05月04日33cloudgamer

我在使用 webpy 时遇到 i18n 问题。

我已经关注了:http://webpy.org/cookbook/i18n_support_in_template_file

所以,在我的 .wsgi 中有:

#i18n 
gettext.install('messages',I18N_PATH,unicode=True) 
gettext.translation('messages',I18N_PATH,languages=['fr_FR','en_US']).install(True) 

所以我跑了:

pygettext.py -a -v -d messages -o i18n/messages.po controllers/*.py views/*.html  

我已经复制并翻译了messages.po,我还更改了“content-type”和“content-transfer-encoding:

"Content-Type: text/plain; charset=utf-8\n" 
"Content-Transfer-Encoding: UTF-8\n" 

然后我运行了这个命令:

msgfmt -v -o i18n/fr_FR/LC_MESSAGES/messages.mo i18n/fr_FR/LC_MESSAGES/messages.po 
>>>93 messages traduits. 

这是 i18n 文件夹的树状图:

i18n/: 
en_US  fr_FR  messages.po 
 
i18n/en_US: 
LC_MESSAGES 
 
i18n/en_US/LC_MESSAGES: 
messages.mo  messages.po 
 
i18n/fr_FR: 
LC_MESSAGES 
 
i18n/fr_FR/LC_MESSAGES: 
messages.mo  messages.po 

但是当我进入我的网站时(我的浏览器的语言是“fr_fr”),我没有翻译字符串。

我也不知道为什么。 有人有想法吗?

谢谢

请您参考如下方法:

web.py 文档在此处对其进行了解释。

http://webpy.org/cookbook/runtime-language-switch