[pygtk] Using gettext, where am I doing mistake

Vláďa vladovi at atlas.cz
Fri May 9 21:38:48 WST 2008


Sorry,

I didn't have much time to look into it lately. Today I spent another 
couple of hours trying to figure out why the translation doesn't work 
for me.

I think the main problem is the path to my .mo file. This is the code I 
now use for testing:

#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gettext
import locale
import os

if os.name == 'nt':
   # windows hack for locale setting
   lang = os.getenv('LANG')
   print lang
   if lang is None:
      default_lang, default_enc = locale.getdefaultlocale()
      if default_lang:
         lang = default_lang
      if lang:
         os.environ['LANG'] = lang

locale.setlocale(locale.LC_ALL,'cz')
gettext.bindtextdomain("translate", "c:/Python/locale")
gettext.textdomain("translate")
_ = gettext.gettext

print gettext.find("translate")

The "find" function should return any matching .mo files. It returns 
None. So I do believe that the problem is somewere in location of the 
.mo file. It is in c:\python\locale\cs\LC_MESSAGES\translate.mo. Is it 
possible to find out at which locations is the gettext extension looking 
for the .mo files?

Thank you,
Vlada

Jarek Zgoda napsal(a):
> Vláďa pisze:
>
>   
>> Thank you for this suggestion, unfortunately it didn't change anything.
>> The function os.getenv('LANG') returns 'cs' for my system. So I do
>> believe the localization file should be placed in
>> locale\cs\LC_MESSAGES\translate.mo. But it doesn't work neither. Do you
>> have any other idea what could be wrong?
>>     
>
> The Windows hack worked for me on W2k and XP with Polish locale, where
> locale.getlocale() returned 'polish_poland'.
>
>   
>> A working sample application would be a huge help for me.
>>     
>
> See eg. http://svn.berlios.de/wsvn/jpa/branches/0.5/bin/jpa.py (I copied
> the code from this module) or Gajim code
> (http://trac.gajim.org/browser/trunk/src/common/i18n.py#L43 and onwards)
> -- it is known to be working on Windows (and is much better established
> than JPA ;)).
>
>   


More information about the pygtk mailing list