13

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

MARTIN Damien
  • 996
  • 2
  • 15
  • 36
  • try locale_path set to full path for example : locale_path="/home/xxx/" – john misoskian Oct 01 '10 at 09:15
  • @john misoskian It doesn't works too... domain argument (1st argument of gettext.translation) is set to 'brainz'. I suppose it is the reference to the filename (brainz.mo). Is it ? – MARTIN Damien Oct 01 '10 at 09:24

1 Answers1

12

I think your __init__.py should be something like:

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()
SilentGhost
  • 307,395
  • 66
  • 306
  • 293
stan
  • 321
  • 3
  • 3