[ python-Bugs-854589 ] Can't use GetText in win32,i386

SourceForge.net noreply at sourceforge.net
Sat Dec 6 10:16:04 EST 2003


Bugs item #854589, was opened at 2003-12-05 09:36
Message generated for change (Settings changed) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=854589&group_id=5470

Category: Extension Modules
Group: Python 2.2
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: ulysses hung (ulyssesh)
Assigned to: Nobody/Anonymous (nobody)
Summary: Can't use GetText in win32,i386

Initial Comment:
hi,

I want to translate my app to Germany use gettext 
module in python22,wxpython.
I have generated pot file, use msgfmt.py 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 at ADDRESS>\n"
"Language-Team: LANGUAGE <LL at li.org>\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 
read 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. 

I enclosed a small app to test it.
ge.mo is good file.  gebad.mo is damage file.
please see the different ge.po with gebad.po.

Thanks.

Ulysses


----------------------------------------------------------------------

Comment By: ulysses hung (ulyssesh)
Date: 2003-12-06 05:06

Message:
Logged In: YES 
user_id=822714

thanks million . my app run ok. Oh my god.
thank you so much .

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-12-05 19:04

Message:
Logged In: YES 
user_id=21627

Please replace the call

trans = gettext.GNUTranslations(open('en.mo'))

with

trans = gettext.GNUTranslations(open('en.mo','rb'))

You must not open .mo files in text mode.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=854589&group_id=5470



More information about the Python-bugs-list mailing list