Python: translation file not found for domain using custom locale folder

I have the following structure:

/ |- main.py |- brainz | |- __init__.py | |- Brainz.py |- datas |- locale |- en_US |- LC_MESSAGES |- brainz.mo |- brainz.po 

My __init__.py has 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 do not understand which path is expected from gettext.translation , as I give the full path to the .mo file.

Can someone explain to me what I need to do to properly upload my translation files?

Thanks,

Damien

+6
python gettext
source share
1 answer

I think your __init__.py should look something like this:

 import locale import gettext import os current_locale, encoding = locale.getdefaultlocale() locale_path = 'datas/locale/' language = gettext.translation ('brainz', locale_path, [current_locale] ) language.install() 
+7
source share

All Articles