472,354 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

gettext on Windows

Hi,

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 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.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')
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.GNUTranslations (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

Oct 28 '06 #1
7 2675
ru******************@googlemail.com wrote:
lan = gettext.GNUTranslations (open (sLang))
are you sure the data file is a text file? what happens if you change
the above to

lan = gettext.GNUTranslations (open (sLang, "rb"))

?

</F>

Oct 28 '06 #2
Fredrik Lundh wrote:
ru******************@googlemail.com wrote:
lan = gettext.GNUTranslations (open (sLang))

are you sure the data file is a text file? what happens if you change
the above to

lan = gettext.GNUTranslations (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.GNUTranslations (open (sLang, "rb"))
File "C:\Python24\lib\gettext.py", line 177, in __init__
self._parse(fp)
File "C:\Python24\lib\gettext.py", line 280, in _parse
raise IOError(0, 'File is corrupt', filename)
IOError: [Errno 0] File is corrupt: 'locale\\fr_FR.mo'

Russ

Oct 28 '06 #3
ru******************@googlemail.com schrieb:
Traceback (most recent call last):
File "panicbutton.py", line 36, in ?
lan = gettext.GNUTranslations (open (sLang, "rb"))
File "C:\Python24\lib\gettext.py", line 177, in __init__
self._parse(fp)
File "C:\Python24\lib\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
Oct 28 '06 #4

Martin v. Lwis wrote:
ru******************@googlemail.com schrieb:
Traceback (most recent call last):
File "panicbutton.py", line 36, in ?
lan = gettext.GNUTranslations (open (sLang, "rb"))
File "C:\Python24\lib\gettext.py", line 177, in __init__
self._parse(fp)
File "C:\Python24\lib\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.GNUTranslations (open (sLang))

to

lan = gettext.GNUTranslations (open (sLang, "rb"))

Without the "rb" in the open () I get a "struct.error : 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

Oct 28 '06 #5

ru******************@googlemail.com wrote:
Martin v. Lwis wrote:
ru******************@googlemail.com schrieb:
Traceback (most recent call last):
File "panicbutton.py", line 36, in ?
lan = gettext.GNUTranslations (open (sLang, "rb"))
File "C:\Python24\lib\gettext.py", line 177, in __init__
self._parse(fp)
File "C:\Python24\lib\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.GNUTranslations (open (sLang))
This code definately corrupts .mo files since on windows files are
opened in text mode by default.
to

lan = gettext.GNUTranslations (open (sLang, "rb"))

Without the "rb" in the open () I get a "struct.error : 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
http://www.gnu.org/software/gettext/...28.html#SEC128
to see if it can convert your files back to text.

-- Leo

Oct 28 '06 #6
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.

Russ

Oct 28 '06 #7
ru******************@googlemail.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
Oct 28 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Patton | last post by:
Can someone point me to a definitive source for the answers to the following two questions: 1) In an environment with Redhat Linux 2.4.21-27.0.1, Apache 1.3.31, PHP 4.3.10, and GNU gettext...
2
by: StasZ | last post by:
Hello, I have some programs which are developed on Linux and uses gettext for the language support. While they run without problem on a win32 platform i haven't a clue how to get the gettext...
2
by: Daniele | last post by:
Dearest, I have a script that I need to localize. 1. step import gettext 2. step
3
by: Rolf Hemmerling | last post by:
Hello ! Beginner's question: Howto access .RC/.RES Ressource files with portable C++ code ( BCC,MSVC,GNU-C++, OpenWatcom) ? I just wanna access "local language strings", so that I may...
13
by: cantabile | last post by:
Hi, I'm failing to make it work but can't find out what's wrong. Here's what I do : ================ test.py import gettext gettext.install('')
1
by: James T. Dennis | last post by:
You'd think that using things like gettext would be easy. Superficially it seems well documented in the Library Reference(*). However, it can be surprisingly difficult to get the external details...
6
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I've encountered a problem using gettext with properties while using a Python interpreter. Here's a simple program that illustrate the problem. ============== # i18n_test.py: test of gettext &...
2
by: paolob | last post by:
Hi to all, I'm running php 5.2.5 on Debian etch, with apache 2.0.56. I need to include, in php.ini, gettext.so library but I didn't find anything. I've already install: apt-get install gettext...
8
by: howa | last post by:
http://hk2.php.net/manual/en/ref.gettext.php I just wonder why those kind of translation/mapping can't be implemented in using plain PHP array? Howard
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.