473,564 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I18n issue with optik

Hi,

I've written a script which uses Optik/Optparse to display the
options (which works fine). The text for the help message is localised
(with german umlauts) and when I execute the script with the localised
environment variable set, I get this traceback[1]. The interesting
thing is that the localised optparse messages from displays fine -
it's only my localisation that errors.

From my understanding, my script doesn't put out anything, it's
optik/optparse who does that. My po file is directly copied from the
optik po file (who displays fine) and modified so the po file should
be fine, too.

What can I do to troubleshoot whether the culprit is my script, optik
or gettext?

Would it make sense to post the script and the mo or po files?
Thorsten

[1]
Traceback (most recent call last):
File "script.py" , line 37, in <module>
options, args = cmdlineparser.p arse_args()
File "/usr/lib/python2.5/optparse.py", line 1378, in parse_args
stop = self._process_a rgs(largs, rargs, values)
File "/usr/lib/python2.5/optparse.py", line 1418, in _process_args
self._process_l ong_opt(rargs, values)
File "/usr/lib/python2.5/optparse.py", line 1493, in
_process_long_o pt
option.process( opt, value, values, self)
File "/usr/lib/python2.5/optparse.py", line 782, in process
self.action, self.dest, opt, value, values, parser)
File "/usr/lib/python2.5/optparse.py", line 804, in take_action
parser.print_he lp()
File "/usr/lib/python2.5/optparse.py", line 1648, in print_help
file.write(self .format_help(). encode(encoding , "replace"))
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xc4 in position
264: ordinal not in range(128)
Mar 31 '07 #1
23 1297
Thorsten Kampe wrote:
I've written a script which uses Optik/Optparse to display the
options (which works fine). The text for the help message is localised
(with german umlauts) and when I execute the script with the localised
environment variable set, I get this traceback[1]. The interesting
thing is that the localised optparse messages from displays fine -
it's only my localisation that errors.

From my understanding, my script doesn't put out anything, it's
optik/optparse who does that. My po file is directly copied from the
optik po file (who displays fine) and modified so the po file should
be fine, too.

What can I do to troubleshoot whether the culprit is my script, optik
or gettext?

Would it make sense to post the script and the mo or po files?
Yes, probably. Though if you can reduce it to the simplest test case
that produces the error, it'll increase your chances of having someone
look at it.

You could also try posting to the optik list:
http://lists.sourceforge.net/lists/listinfo/optik-users

STeVe
Apr 1 '07 #2
* Steven Bethard (Sat, 31 Mar 2007 20:08:45 -0600)
Thorsten Kampe wrote:
I've written a script which uses Optik/Optparse to display the
options (which works fine). The text for the help message is localised
(with german umlauts) and when I execute the script with the localised
environment variable set, I get this traceback[1]. The interesting
thing is that the localised optparse messages from displays fine -
it's only my localisation that errors.

From my understanding, my script doesn't put out anything, it's
optik/optparse who does that. My po file is directly copied from the
optik po file (who displays fine) and modified so the po file should
be fine, too.

What can I do to troubleshoot whether the culprit is my script, optik
or gettext?

Would it make sense to post the script and the mo or po files?

Yes, probably. Though if you can reduce it to the simplest test case
that produces the error, it'll increase your chances of having someone
look at it.
The most simple test.py is:

###
#! /usr/bin/env python

import gettext, \
os, \
sys

gettext.textdom ain('optparse')
gettext.install ('test')

from optparse import OptionParser, \
OptionGroup

cmdlineparser = OptionParser(de scription = _('THIS SOFTWARE COMES
WITHOUT WARRANTY, LIABILITY OR SUPPORT!'))

options, args = cmdlineparser.p arse_args()
###

When I run LANGUAGE=de ./test.py --help I get the error.

### This is the test.de.po file
# Copyright (C) 2006 Thorsten Kampe
# Thorsten Kampe <th******@thors tenkampe.de>, 2006

msgid ""
msgstr ""

"Project-Id-Version: Template 1.0\n"
"POT-Creation-Date: Tue Sep 7 22:20:34 2004\n"
"PO-Revision-Date: 2005-07-03 16:47+0200\n"
"Last-Translator: Thorsten Kampe <th******@thors tenkampe.de>\n"
"Language-Team: Thorsten Kampe <th******@thors tenkampe.de>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-15\n"
"Content-Transfer-Encoding: 8-bit\n"
"Generated-By: pygettext.py 1.5\n"

msgid "THIS SOFTWARE COMES WITHOUT WARRANTY, LIABILITY OR SUPPORT!"
msgstr "DIESES PROGRAMM HAT WEDER GEWÄHRLEISTUNG, HAFTUNG NOCH
UNTERSTÜTZUNG!"
###

The localisation now produces an error in the localised optik files,
too.

Under Windows I get " File "G:\program files\python\li b\encodings
\cp1252.py", line 12, in encode
return codecs.charmap_ encode(input,er rors,encoding_t able)"

Is there something I have to do to put the terminal in "non-ascii
output mode"?

I tried

###
#! /usr/bin/env python
# -*- coding: ISO-8859-15 -*-

print "DIESES PROGRAMM HAT WEDER GEWÄHRLEISTUNG, HAFTUNG NOCH
UNTERSTÜTZUNG!"
###

....and this worked. That means that my terminal is willing to print,
right?!
You could also try posting to the optik list:
http://lists.sourceforge.net/lists/listinfo/optik-users
I already did this via Gmane (although the list seems pretty dead to
me). Sourceforge seems to have a bigger problem as [1] and [2] error.

Sorry for the confusion but this Unicode magic is far from being
rational. I guess most people just don't get it...
Thorsten
[1] http://sourceforge.net/mailarchive/f...um=optik-users
[2] https://lists.sourceforge.net/lists/listinfo
Apr 1 '07 #3
Just an addition : when I insert this statement...

print _('THIS SOFTWARE COMES WITHOUT WARRANTY, LIABILITY OR SUPPORT!')

into this skript, the line is printed out. So if my Skript can output
the localised text but Optparse can't it should be an optparse bug,
right?!

Thorsten
Apr 1 '07 #4
I guess the culprit is this snippet from optparse.py:

# used by test suite
def _get_encoding(s elf, file):
encoding = getattr(file, "encoding", None)
if not encoding:
encoding = sys.getdefaulte ncoding()
return encoding

def print_help(self , file=None):
"""print_help(f ile : file = stdout)

Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
"""
if file is None:
file = sys.stdout
encoding = self._get_encod ing(file)
file.write(self .format_help(). encode(encoding , "replace"))

So this means: when the encoding of sys.stdout is US-ASCII, Optparse
sets the encoding to of the help text to ASCII, too. But that's
nonsense because the Encoding is declared in the Po (localisation)
file.

How can I set the encoding of sys.stdout to another encoding? Of
course this would be a terrible hack if the encoding of the
localisation changes or different translators use different
encodings...

Thorsten
Apr 1 '07 #5
Thorsten Kampe wrote:
* Steven Bethard (Sat, 31 Mar 2007 20:08:45 -0600)
>Thorsten Kampe wrote:
>>I've written a script which uses Optik/Optparse to display the
options (which works fine). The text for the help message is localised
(with german umlauts) and when I execute the script with the localised
environment variable set, I get this traceback[1]. The interesting
thing is that the localised optparse messages from displays fine -
it's only my localisation that errors.

From my understanding, my script doesn't put out anything, it's
optik/optparse who does that. My po file is directly copied from the
optik po file (who displays fine) and modified so the po file should
be fine, too.

What can I do to troubleshoot whether the culprit is my script, optik
or gettext?

Would it make sense to post the script and the mo or po files?
Yes, probably. Though if you can reduce it to the simplest test case
that produces the error, it'll increase your chances of having someone
look at it.

The most simple test.py is:

###
#! /usr/bin/env python

import gettext, \
os, \
sys

gettext.textdom ain('optparse')
gettext.install ('test')

from optparse import OptionParser, \
OptionGroup

cmdlineparser = OptionParser(de scription = _('THIS SOFTWARE COMES
WITHOUT WARRANTY, LIABILITY OR SUPPORT!'))

options, args = cmdlineparser.p arse_args()
###

When I run LANGUAGE=de ./test.py --help I get the error.

### This is the test.de.po file
# Copyright (C) 2006 Thorsten Kampe
# Thorsten Kampe <th******@thors tenkampe.de>, 2006

msgid ""
msgstr ""

"Project-Id-Version: Template 1.0\n"
"POT-Creation-Date: Tue Sep 7 22:20:34 2004\n"
"PO-Revision-Date: 2005-07-03 16:47+0200\n"
"Last-Translator: Thorsten Kampe <th******@thors tenkampe.de>\n"
"Language-Team: Thorsten Kampe <th******@thors tenkampe.de>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-15\n"
"Content-Transfer-Encoding: 8-bit\n"
"Generated-By: pygettext.py 1.5\n"

msgid "THIS SOFTWARE COMES WITHOUT WARRANTY, LIABILITY OR SUPPORT!"
msgstr "DIESES PROGRAMM HAT WEDER GEWÄHRLEISTUNG, HAFTUNG NOCH
UNTERSTÜTZUNG!"
###

The localisation now produces an error in the localised optik files,
too.

Under Windows I get " File "G:\program files\python\li b\encodings
\cp1252.py", line 12, in encode
return codecs.charmap_ encode(input,er rors,encoding_t able)"
I'm not very experienced with internationaliz ation, but if you change::

gettext.install ('test')

to::

gettext.install ('test', unicode=True)

what happens?

STeVe
Apr 1 '07 #6
Thorsten Kampe wrote:
I guess the culprit is this snippet from optparse.py:

# used by test suite
def _get_encoding(s elf, file):
encoding = getattr(file, "encoding", None)
if not encoding:
encoding = sys.getdefaulte ncoding()
return encoding

def print_help(self , file=None):
"""print_help(f ile : file = stdout)

Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
"""
if file is None:
file = sys.stdout
encoding = self._get_encod ing(file)
file.write(self .format_help(). encode(encoding , "replace"))

So this means: when the encoding of sys.stdout is US-ASCII, Optparse
sets the encoding to of the help text to ASCII, too. But that's
nonsense because the Encoding is declared in the Po (localisation)
file.

How can I set the encoding of sys.stdout to another encoding? Of
course this would be a terrible hack if the encoding of the
localisation changes or different translators use different
encodings...
If print_help() is what's wrong, you should probably hack print_help()
instead of sys.stdout. You could try something like::

def print_help(self , file=None):
"""print_help(f ile : file = stdout)

Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
"""
if file is None:
file = sys.stdout
file.write(self .format_help())

optparse.Option Parser.print_he lp = print_help

cmdlineparser = optparse.Option Parser(descript ion=...)
...

That is, you could monkey-patch print_help() before you create an
OptionParser.

STeVe
Apr 1 '07 #7
* Steven Bethard (Sun, 01 Apr 2007 10:21:40 -0600)
Thorsten Kampe wrote:
* Steven Bethard (Sat, 31 Mar 2007 20:08:45 -0600)
Thorsten Kampe wrote:
I've written a script which uses Optik/Optparse to display the
options (which works fine). The text for the help message is localised
(with german umlauts) and when I execute the script with the localised
environment variable set, I get this traceback[1]. The interesting
thing is that the localised optparse messages from displays fine -
it's only my localisation that errors.

From my understanding, my script doesn't put out anything, it's
optik/optparse who does that. My po file is directly copied from the
optik po file (who displays fine) and modified so the po file should
be fine, too.

What can I do to troubleshoot whether the culprit is my script, optik
or gettext?

Would it make sense to post the script and the mo or po files?
Yes, probably. Though if you can reduce it to the simplest test case
that produces the error, it'll increase your chances of having someone
look at it.
The most simple test.py is:

###
#! /usr/bin/env python

import gettext, \
os, \
sys

gettext.textdom ain('optparse')
gettext.install ('test')

from optparse import OptionParser, \
OptionGroup

cmdlineparser = OptionParser(de scription = _('THIS SOFTWARE COMES
WITHOUT WARRANTY, LIABILITY OR SUPPORT!'))

options, args = cmdlineparser.p arse_args()
###

When I run LANGUAGE=de ./test.py --help I get the error.

### This is the test.de.po file
# Copyright (C) 2006 Thorsten Kampe
# Thorsten Kampe <th******@thors tenkampe.de>, 2006

msgid ""
msgstr ""

"Project-Id-Version: Template 1.0\n"
"POT-Creation-Date: Tue Sep 7 22:20:34 2004\n"
"PO-Revision-Date: 2005-07-03 16:47+0200\n"
"Last-Translator: Thorsten Kampe <th******@thors tenkampe.de>\n"
"Language-Team: Thorsten Kampe <th******@thors tenkampe.de>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-15\n"
"Content-Transfer-Encoding: 8-bit\n"
"Generated-By: pygettext.py 1.5\n"

msgid "THIS SOFTWARE COMES WITHOUT WARRANTY, LIABILITY OR SUPPORT!"
msgstr "DIESES PROGRAMM HAT WEDER GEWÄHRLEISTUNG, HAFTUNG NOCH
UNTERSTÜTZUNG!"
###

The localisation now produces an error in the localised optik files,
too.

Under Windows I get " File "G:\program files\python\li b\encodings
\cp1252.py", line 12, in encode
return codecs.charmap_ encode(input,er rors,encoding_t able)"

I'm not very experienced with internationaliz ation, but if you change::

gettext.install ('test')

to::

gettext.install ('test', unicode=True)

what happens?
No traceback anymore from optparse but the non-ascii umlauts are
displayed as question marks ("?").

Thorsten
Apr 1 '07 #8
* Steven Bethard (Sun, 01 Apr 2007 10:26:54 -0600)
Thorsten Kampe wrote:
I guess the culprit is this snippet from optparse.py:

# used by test suite
def _get_encoding(s elf, file):
encoding = getattr(file, "encoding", None)
if not encoding:
encoding = sys.getdefaulte ncoding()
return encoding

def print_help(self , file=None):
"""print_help(f ile : file = stdout)

Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
"""
if file is None:
file = sys.stdout
encoding = self._get_encod ing(file)
file.write(self .format_help(). encode(encoding , "replace"))

So this means: when the encoding of sys.stdout is US-ASCII, Optparse
sets the encoding to of the help text to ASCII, too. But that's
nonsense because the Encoding is declared in the Po (localisation)
file.

How can I set the encoding of sys.stdout to another encoding? Of
course this would be a terrible hack if the encoding of the
localisation changes or different translators use different
encodings...

If print_help() is what's wrong, you should probably hack print_help()
instead of sys.stdout. You could try something like::

def print_help(self , file=None):
"""print_help(f ile : file = stdout)

Print an extended help message, listing all options and any
help text provided with them, to 'file' (default stdout).
"""
if file is None:
file = sys.stdout
file.write(self .format_help())

optparse.Option Parser.print_he lp = print_help

cmdlineparser = optparse.Option Parser(descript ion=...)
...

That is, you could monkey-patch print_help() before you create an
OptionParser.
Yes, I could do that but I'd rather know first if my code is wrong or
the optparse code.

Thorsten
Apr 1 '07 #9
* Thorsten Kampe (Sun, 1 Apr 2007 19:45:59 +0100)
Yes, I could do that but I'd rather know first if my code is wrong or
the optparse code.
It might be the bug mentioned in
http://mail.python.org/pipermail/pyt...ay/065458.html

The patch although doesn't work. From my unicode-charset-codepage-
codeset-challenged point of view the encoding of sys.stdout doesn't
matter. The charset is defined in the .po/.mo file (but of course
optparse can't know if the message has been translated by gettext
("_").

Thorsten
Apr 1 '07 #10

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

Similar topics

10
2967
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web (basically from everywhere) store it and properly serve it back to users, . . .? . Can you point me to info on this? I would preferably use...
0
1249
by: Laszlo Zsolt Nagy | last post by:
Hello, I wonder if there is a standard for making i18n in Python projects. I have several Python projects that are internationalized. I also have Python packages with i18n. But it is still not clean to me what is the recommended way to do it. Currently, I use a module called 'localization.py' with this code: from i18n_domain import...
10
3714
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web (basically from everywhere) store it and properly serve it back to users, . . .? . Can you point me to info on this? I would preferably use...
4
1409
by: Donn Ingle | last post by:
Hi, A soon-to-be happy new year to everyone! I'm 100% new to this i18n lark and my approach so far has been to create a .mo file per module in my app. My thinking was, why load one huge .mo file when a single module only needs a few strings? Since then, it seems, I have made the wrong decision. For example I have module A that imports...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
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. ...
0
8106
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...
1
7642
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...
0
6255
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...
0
5213
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...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
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...

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.