[I18n-sig] Problem using gettext
Werner F. Bruhin
werner.bruhin at free.fr
Tue May 17 10:48:48 CEST 2005
Hi Philippe,
I think you are missing the "install" step, I do the following:
import gettext
gettext.install('twcb', os.path.join(os.getcwd(), 'locale'), unicode=0)
localeDir = os.path.join(os.getcwd(), 'locale')
langEn = gettext.translation('twcb', localeDir, languages=['en'])
langFr = gettext.translation('twcb', localeDir, languages=['fr'])
langDe = gettext.translation('twcb', localeDir, languages=['de'])
locale.setlocale(locale.LC_ALL, '')
Above is done just after other imports.
Then I have a function which selects the appropriate lang like this:
def SetLang(self, lang):
if lang in ['fr']:
langFr.install()
elif lang in ['de']:
langDe.install()
else:
langEn.install()
Hope this helps.
Werner
Philippe Collet wrote:
> Hi list,
> Hope i'm in the good list.
> I'm having problem using gettext.
> import gettext
> domain = 'test'
> dir='C:\\Documents and Settings\\Philippe\\Bureau\\test'
> lang = 'fr'
> t=gettext.translation(domain,dir,lang)
>
> I generated with pygettext.py the .pot file, i fill the msgstr line. I
> rename it in test.po and i generate the .mo file with msgfmt.py.
>
> I'm sure the following path is correct.
> C:\Documents and Settings\Philippe\Bureau\test\fr\LC_MESSAGES\test.mo.
>
> I'm having next error:
>
> Traceback (most recent call last):
> File
> "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
> exec codeObject in __main__.__dict__
> File "C:\Documents and Settings\Philippe\Bureau\test\test.py", line 6, in
> ?
> t=gettext.translation(domaine,repBase)
> File "C:\Python23\lib\gettext.py", line 405, in translation
> raise IOError(ENOENT, 'No translation file found for domain', domain)
> IOError: [Errno 2] No translation file found for domain: 'test'.
>
> My Python version: ActiveState ActivePython 2.3.5
> OS: Window XP SP2
>
> I think there is a problem in the find function because it's returning
> always None, even if the path is correct and the file .mo found.
>
> I tryed to use directly the find function in the gettext.py file without
> success
>
>>>>print gettext.find(domain, dir, lang)
>
> None
>
> By inspecting this function i tryied to test the validity of the path:
>
>>>>if os.path.exists(os.path.join(dir, lang, 'LC_MESSAGES', '%s.mo' %
>>>>domain)):
>
> ... print 'ok'
> ...
> ok
>
> Can anyone help me please?,
> Philippe Collet
>
> _________________________________________________________________
> MSN Messenger : discutez en direct avec vos amis !
> http://www.msn.fr/msger/default.asp
More information about the I18n-sig
mailing list