[Tutor] gettext mystery

Kent Johnson kent_johnson at skillsoft.com
Thu Nov 4 18:04:15 CET 2004


If you print gettext.__file__ it will show you where it was loaded from. If 
you are loading two different modules that will show them you you.

Kent

At 12:14 PM 11/4/2004 +0100, Michael Lange wrote:
>Hi,
>
>I've been playing a ittle with the gettext module, trying to add a german 
>translation to
>Moleskine; from reading the docs I thought all I would have to do was 
>creating a mo file
>and then adding the magic lines
>
>import gettext
>gettext.install('moleskine', '/usr/share/locale')
>
>to the main program file.
>
>I found that Moleskine's author had already tried to implement gettext 
>support, but has given
>up for some reason, so I added these lines in the module where he had started
>(in site-packages/Moleskine/__init__.py); the result:
>
>Traceback (most recent call last):
>   File "/usr/bin/moleskine", line 41, in ?
>     import Moleskine
>   File "/usr/lib/python2.2/site-packages/Moleskine/__init__.py", line 29, 
> in ?
>     gettext.install(domain, locale_dir)
>AttributeError: 'module' object has no attribute 'install'
>
>I changed the second line and wrote:
>
>import gettext
>print dir(gettext)
>
>and here's what I get:
>
>[pingu at localhost pingu]$ moleskine
>['Catalog', '_', '__builtins__', '__doc__', '__file__', '__name__', 
>'_aliases', '_cat', '_cats', '_expand_lang', '_intToLsbStr', 
>'_lsbStrToInt', '_msbStrToInt', '_unalias_lang', 'bindtextdomain', 
>'dgettext', 'env', 'error', 'gettext', 'lang', 'localedir', 'os', 
>'prefix', 'string', 'test', 'textdomain']
>
>Then I tried putting the gettext import into the main file 
>(/usr/bin/moleskine) instead of __init__.py and the print
>statement gave me the expected output:
>
>[pingu at localhost pingu]$ moleskine
>['Catalog', 'ENOENT', 'GNUTranslations', 'NullTranslations', '__all__', 
>'__builtins__', '__doc__', '__file__', '__name__', '_current_domain', 
>'_default_localedir', '_expand_lang', '_localedirs', '_translations', 
>'bindtextdomain', 'dgettext', 'find', 'gettext', 'install', 'os', 
>'struct', 'sys', 'textdomain', 'translation']
>
>Does anyone have a clue why gettext shows a different behavior depending 
>on where it's imported?
>I *think* it might have something to do with GNOME (some menu items are 
>already translated although there
>is no german mo file, can GNOME do so automagically?) but it looks like in 
>fact I've been importing
>two different modules, which I found quite confusing.
>
>Any pointers are appreciated.
>
>Thanks
>
>Michael
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list