gettext on Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • russ.phillips.nospam@googlemail.com

    #1

    gettext on Windows

    Hi,

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

    "Traceback (most recent call last):
    file PanicButton.py 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>
    # Code to find & install l10n file
    import gettext, os, locale, glob
    loc = locale.getdefau ltlocale ()
    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')
    else:
    #find a .mo file that matches the first part (first three
    characters) of the locale
    sMoFiles = glob.glob (os.path.join ('locale', sLocale [:3] +
    '*.mo'))
    if (len (sMoFiles) 0):
    sLang = sMoFiles [0]
    else:
    #Could not find exact or partial match for locale - use default
    translation file (British English)
    sLang = os.path.join ('locale', 'en_GB.mo')

    lan = gettext.GNUTran slations (open (sLang))
    lan.install ()
    # End of code to find & install l10n file
    </code>

    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 SF.net project page [1], if
    required.

    Russ

    [1] http://sourceforge.net/projects/panicbutton

  • Fredrik Lundh

    #2
    Re: gettext on Windows

    russ.phillips.n ospam@googlemai l.com wrote:
    lan = gettext.GNUTran slations (open (sLang))
    are you sure the data file is a text file? what happens if you change
    the above to

    lan = gettext.GNUTran slations (open (sLang, "rb"))

    ?

    </F>

    Comment

    • russ.phillips.nospam@googlemail.com

      #3
      Re: gettext on Windows

      Fredrik Lundh wrote:
      russ.phillips.n ospam@googlemai l.com wrote:
      >
      lan = gettext.GNUTran slations (open (sLang))
      >
      are you sure the data file is a text file? what happens if you change
      the above to
      >
      lan = gettext.GNUTran slations (open (sLang, "rb"))
      The .mo files aren't text files, they're binary, but when I make that
      change, I get this error message:

      Traceback (most recent call last):
      File "panicbutton.py ", line 36, in ?
      lan = gettext.GNUTran slations (open (sLang, "rb"))
      File "C:\Python24\li b\gettext.py", line 177, in __init__
      self._parse(fp)
      File "C:\Python24\li b\gettext.py", line 280, in _parse
      raise IOError(0, 'File is corrupt', filename)
      IOError: [Errno 0] File is corrupt: 'locale\\fr_FR. mo'

      Russ

      Comment

      • Martin v. Löwis

        #4
        Re: gettext on Windows

        russ.phillips.n ospam@googlemai l.com schrieb:
        Traceback (most recent call last):
        File "panicbutton.py ", line 36, in ?
        lan = gettext.GNUTran slations (open (sLang, "rb"))
        File "C:\Python24\li b\gettext.py", line 177, in __init__
        self._parse(fp)
        File "C:\Python24\li b\gettext.py", line 280, in _parse
        raise IOError(0, 'File is corrupt', filename)
        IOError: [Errno 0] File is corrupt: 'locale\\fr_FR. mo'
        If it says so, it likely is right. How did you create the file?

        Regards,
        Martin

        Comment

        • russ.phillips.nospam@googlemail.com

          #5
          Re: gettext on Windows


          Martin v. Löwis wrote:
          russ.phillips.n ospam@googlemai l.com schrieb:
          Traceback (most recent call last):
          File "panicbutton.py ", line 36, in ?
          lan = gettext.GNUTran slations (open (sLang, "rb"))
          File "C:\Python24\li b\gettext.py", line 177, in __init__
          self._parse(fp)
          File "C:\Python24\li b\gettext.py", line 280, in _parse
          raise IOError(0, 'File is corrupt', filename)
          IOError: [Errno 0] File is corrupt: 'locale\\fr_FR. mo'
          >
          If it says so, it likely is right. How did you create the file?
          I only get the "File is corrupt" error when I changed

          lan = gettext.GNUTran slations (open (sLang))

          to

          lan = gettext.GNUTran slations (open (sLang, "rb"))

          Without the "rb" in the open () I get a "struct.err or : unpack str size
          does not match format" error (see original post).

          The .mo files were created using poEdit (www.poedit.org), and I get the
          same error with various translations, all created by different people.

          Russ

          Comment

          • Leo Kislov

            #6
            Re: gettext on Windows


            russ.phillips.n ospam@googlemai l.com wrote:
            Martin v. Löwis wrote:
            russ.phillips.n ospam@googlemai l.com schrieb:
            Traceback (most recent call last):
            File "panicbutton.py ", line 36, in ?
            lan = gettext.GNUTran slations (open (sLang, "rb"))
            File "C:\Python24\li b\gettext.py", line 177, in __init__
            self._parse(fp)
            File "C:\Python24\li b\gettext.py", line 280, in _parse
            raise IOError(0, 'File is corrupt', filename)
            IOError: [Errno 0] File is corrupt: 'locale\\fr_FR. mo'
            If it says so, it likely is right. How did you create the file?
            >
            I only get the "File is corrupt" error when I changed
            >
            lan = gettext.GNUTran slations (open (sLang))
            This code definately corrupts .mo files since on windows files are
            opened in text mode by default.
            to
            >
            lan = gettext.GNUTran slations (open (sLang, "rb"))
            >
            Without the "rb" in the open () I get a "struct.err or : unpack str size
            does not match format" error (see original post).
            struct.error usually means input data doesn't correspond to expected
            format.
            The .mo files were created using poEdit (www.poedit.org), and I get the
            same error with various translations, all created by different people.
            Try msgunfmt

            to see if it can convert your files back to text.

            -- Leo

            Comment

            • russ.phillips.nospam@googlemail.com

              #7
              Re: gettext on Windows

              Leo Kislov wrote:
              Try msgunfmt

              to see if it can convert your files back to text.
              Just tried it, and it was able to convert each of the .mo files back to
              text without any problems.

              Russ

              Comment

              • Martin v. Löwis

                #8
                Re: gettext on Windows

                russ.phillips.n ospam@googlemai l.com schrieb:
                Leo Kislov wrote:
                >
                >Try msgunfmt
                >http://www.gnu.org/software/gettext/...28.html#SEC128
                >to see if it can convert your files back to text.
                >
                Just tried it, and it was able to convert each of the .mo files back to
                text without any problems.
                Then you should make a bug report (or, better yet, a patch). Apparently,
                the Python gettext implementation is not able to process the MO files
                you are passing.

                Regards,
                Martin

                Comment

                Working...