gettext crazy question

U

ulysses

hi,

I want to translate my app to Chinese use gettext module in python22,wxpython.
I have get pot file, use msgfmt convert to mo file. But if I type some line
character , app can't load MO file.
trans = gettext.GNUTranslations(open('en.mo'))
raise a error , error message is "unpack str size does not match format"

exp:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: Mon Aug 25 16:40:30 2003\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=iso-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"

#: AboutForm.py:56
msgid "Author"
msgstr "chinese character"

#: AboutForm.py:62
msgid "Donate To"
msgstr ""

#: AboutForm.py:70
msgid "Close"
msgstr "chinese character"

If i don't fill 62 , app is ok.

So I debug gettext module. I find following interest question.
-=gettext line 154=-
buf = fp.read()

I sure fp(file object) has open.

It can't read all binary code. buf 's lengh smaller than real file.
exp ,whole file 1000 byte. gettext only read 187 .

So raise unpack error at gettext line 167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tlen, toff = unpack(ii, buf[transidx:transidx+8])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Because request transidx doesn't exit.

then I remove 62 line ,left empty. App can work.
I open the mo file by ultraedit and compare the different .
I notice the read function broken position bytecode is 0x1A
but good mo same position is 0x0A. so I change the bad mo to 0A.
It's work.

It's really crazy .I don't know where and why I get failure.
If you help us explain the puzzle I very appreciate.

Ulysses
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

So I debug gettext module. I find following interest question.
-=gettext line 154=-
buf = fp.read()

I sure fp(file object) has open.

It can't read all binary code. buf 's lengh smaller than real file.
exp ,whole file 1000 byte. gettext only read 187 .

It looks like the file is opened in text mode, not in binary mode.

Did you, by chance, open the file yourself? You should use binary
mode, then.

Regards,
Martin
 
U

ulysses

It looks like the file is opened in text mode, not in binary mode.

Did you, by chance, open the file yourself? You should use binary
mode, then.

Regards,
Martin


I use same statement open file. different is MO file.
when don't fill some line, gettext can open mo normally.
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

I use same statement open file. different is MO file.
when don't fill some line, gettext can open mo normally.

Can you please post a bug report to SourceForge then? Please include
the .mo file, and a small Python script showing the error.

Regards,
Martin
 
U

ulysses

Can you please post a bug report to SourceForge then? Please include
the .mo file, and a small Python script showing the error.

Regards,
Martin

Do you mean http://gettext.sourceforge.net/ ?
Can I Email to you , sample script and MO file.
I promise It's very small . I don't how to write to SF.
Somebody help me translate my app (turbobt) www.turbobt.com to germany.
But I meet same question. Use iso8859-1,8BIT.
If mo file have 0x1A char, gettext can't load it.
Thanks.

Ulysses
 
U

ulysses

Dear sir,

I post a bug report with demo app in python in SF.
Track Number is 854589 ,subject is "Can't use GetText in win32,i386" .
Please help me. Thanks.

Ulysses
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

I post a bug report with demo app in python in SF.
Track Number is 854589 ,subject is "Can't use GetText in win32,i386" .
Please help me. Thanks.

See the SF report. You need to open mo files in binary mode.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top