Python:使用自定义区域设置文件夹找不到域的翻译文件
我有以下结构:
/
|- main.py
|- brainz
| |- __init__.py
| |- Brainz.py
|- datas
|- locale
|- en_US
|- LC_MESSAGES
|- brainz.mo
|- brainz.po
在我的 __init__.py
中有以下几行:
import locale
import gettext
import os
current_locale, encoding = locale.getdefaultlocale()
locale_path = '../datas/locale/' + current_locale + '/LC_MESSAGES/'
language = gettext.translation ( 'brainz', locale_path )
language.install()
但是当我尝试运行我的程序时,我收到此错误:
Traceback (most recent call last):
File "main.py", line 3, in <module>
from brainz.Brainz import *
File "/home/damien/BrainZ/brainz/__init__.py", line 11, in <module>
language = gettext.translation ( 'brainz', locale_path )
File "/usr/lib/python2.6/gettext.py", line 484, in translation
raise IOError(ENOENT, 'No translation file found for domain', domain)
IOError: [Errno 2] No translation file found for domain: 'brainz'
我不明白 需要哪个路径gettext.translation
因为我给出了 .mo
文件的完整路径。
有人可以解释一下我必须做什么才能正确加载翻译文件吗?
谢谢,
达米安
I have the following structure :
/
|- main.py
|- brainz
| |- __init__.py
| |- Brainz.py
|- datas
|- locale
|- en_US
|- LC_MESSAGES
|- brainz.mo
|- brainz.po
In my __init__.py
there is the following lines :
import locale
import gettext
import os
current_locale, encoding = locale.getdefaultlocale()
locale_path = '../datas/locale/' + current_locale + '/LC_MESSAGES/'
language = gettext.translation ( 'brainz', locale_path )
language.install()
But when I try to run my program I got this error :
Traceback (most recent call last):
File "main.py", line 3, in <module>
from brainz.Brainz import *
File "/home/damien/BrainZ/brainz/__init__.py", line 11, in <module>
language = gettext.translation ( 'brainz', locale_path )
File "/usr/lib/python2.6/gettext.py", line 484, in translation
raise IOError(ENOENT, 'No translation file found for domain', domain)
IOError: [Errno 2] No translation file found for domain: 'brainz'
I don't understand which path is expected by gettext.translation
as I give a complete path to the .mo
file.
Could someone explain me what I have to do to load my translation files correctly ?
Thanks,
Damien
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的 __init__.py 应该是这样的:
I think your
__init__.py
should be something like: