473,699 Members | 2,364 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Oct 28 '06 #1
7 2787
ru************* *****@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>

Oct 28 '06 #2
Fredrik Lundh wrote:
ru************* *****@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

Oct 28 '06 #3
ru************* *****@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
Oct 28 '06 #4

Martin v. Löwis wrote:
ru************* *****@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

Oct 28 '06 #5

ru************* *****@googlemai l.com wrote:
Martin v. Löwis wrote:
ru************* *****@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
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************* *****@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
Oct 28 '06 #8

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

Similar topics

1
3630
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 0.14.1, will using PHP's gettext support along with the GNU gettext utilities work properly? For example, I've seen references to the translated strings in .mo files not always being what appears
2
2044
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 stuff working. Also locale settings are different. Can somebody give me some pointers on how this sort of thing is implemented in windows?
2
2164
by: Daniele | last post by:
Dearest, I have a script that I need to localize. 1. step import gettext 2. step
3
6751
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 replace the ..RC file to compile a version of my software for a different language.
13
3938
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
3243
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 right. * http://docs.python.org/lib/node738.html Here's what I finally came up with as the simplest instructions, suitable for an "overview of Python programming" class: Start with the venerable "Hello, World!" program ... slightly modified
6
2024
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 & properties import gettext fr = gettext.translation('i18n_test', './translations',
2
4422
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 apt-get install php-gettext apt-get install php5-cli apt-get install php5 php5-common
8
3377
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
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8884
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.