gettext on Windows

russ.phillips.nospam at russ.phillips.nospam at
Sat Oct 28 04:04:29 EDT 2006


I'm trying to use gettext to internationalise my project [1], but I'm
getting the following error message with some translations:

"Traceback (most recent call last):
file line 36 in ?
file Gettext.pyc line 177 in _init_
file Gettext.pyc line 274 in _parse
struct.error : unpack str size does not match format"

The snippet of code that loads the .mo file is below:

# Code to find & install l10n file
import gettext, os, locale, glob
loc = locale.getdefaultlocale ()
sLocale = loc [0]

#Use translation file with same name as locale if it exists
if (os.path.exists (os.path.join ('locale', sLocale + '.mo'))):
    sLang = os.path.join ('locale', sLocale + '.mo')
    #find a .mo file that matches the first part (first three
characters) of the locale
    sMoFiles = glob.glob (os.path.join ('locale', sLocale [:3] +
    if (len (sMoFiles) > 0):
        sLang = sMoFiles [0]
        #Could not find exact or partial match for locale - use default
translation file (British English)
        sLang = os.path.join ('locale', '')

lan = gettext.GNUTranslations (open (sLang))
lan.install ()
# End of code to find & install l10n file

I *think* the problem is a unicode problem - it only seems to appear
when the translated file uses unicode strings.

Is the problem in the code that loads the .mo file - do I need to make
it use unicode? Or do the strings that are to be translated have to be
marked as unicode?

Full sourcecode is available via the project page [1], if



More information about the Python-list mailing list