473,698 Members | 2,393 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
23 1316
* paul (Mon, 02 Apr 2007 17:49:15 +0200)
Thorsten Kampe schrieb:
[snipp]
I got the tip to set a different encoding by
sys.stdout = codecs.EncodedF ile(sys.stdout, 'utf-8')

but unfortunately this does not change the encoding of any Terminal.
So my question is: how can I set a different encoding to sys.stdout
(or why can I set it without any error but nothing changes?)
AFAIK you can't. If the terminal is limited to ascii it won't be able to
display anything else; it might not even have the right font, so how are
you supposed to fix that?
Actually rxvt, Poderosa and console have the ability to display non-
ASCII characters. I use the dejavu fonts that support non-ASCII, too.

But the problem is even simpler: I can't even set the standard Windows
console ("cmd") to Windows 1252 in Python. Although directly executing
"chcp 1252" works.

Thorsten
Apr 2 '07 #21
Actually rxvt, Poderosa and console have the ability to display non-
ASCII characters. I use the dejavu fonts that support non-ASCII, too.

But the problem is even simpler: I can't even set the standard Windows
console ("cmd") to Windows 1252 in Python. Although directly executing
"chcp 1252" works.
Maybe try to use http://sourceforge.net/projects/console it's claimed to be
muc better than the sucky CDM (I don't have windows to try it).
--
damjan
Apr 2 '07 #22
* Damjan (Mon, 02 Apr 2007 18:29:06 +0200)
Actually rxvt, Poderosa and console have the ability to display non-
ASCII characters. I use the dejavu fonts that support non-ASCII, too.

But the problem is even simpler: I can't even set the standard Windows
console ("cmd") to Windows 1252 in Python. Although directly executing
"chcp 1252" works.

Maybe try to use http://sourceforge.net/projects/console it's claimed to be
muc better than the sucky CDM (I don't have windows to try it).
It is definitely. But it just runs bash or cmd.exe so its capabilities
(encoding) are defined by Windows or Cygwin.

Thorsten
Apr 2 '07 #23
* Thorsten Kampe (Mon, 2 Apr 2007 16:05:25 +0100)
* Steven Bethard (Sun, 01 Apr 2007 10:21:40 -0600)
Thorsten Kampe wrote:
I'm not very experienced with internationaliz ation, but if you change::

gettext.install ('test')

to::

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

what happens?

Actually, this is the solution.

But there's one more problem: the solution only works when the
Terminal encoding is not US-ASCII. Unfortunately (almost) all
terminals I tried are set to US-ASCII (rxvt under Cygwin, Console[1]
running bash, Poderosa[2] running bash). Only the Windows Console is
CP852 and this works.

I got the tip to set a different encoding by
sys.stdout = codecs.EncodedF ile(sys.stdout, 'utf-8')

but unfortunately this does not change the encoding of any Terminal.
So my question is: how can I set a different encoding to sys.stdout
(or why can I set it without any error but nothing changes?)
I solved it (finally after two days with the help of a lot of people):

You have to set this...

sys.stdout = codecs.EncodedF ile(sys.stdout, 'iso-8859-15')
sys.stdout.enco ding = 'iso-8859-15'

....both of these and exactly in this order and not vice versa. It
doesn't have to be 'iso-8859-15', Windows-1252 is fine, too (but UTF-8
doesn't work). Now we have a new problem: the native Windows consoles
don't print the right characters. So you wrap this in a query:

if sys.platform in ['cygwin', 'linux2']:
sys.stdout = codecs.EncodedF ile(sys.stdout, 'iso-8859-15')
sys.stdout.enco ding = 'iso-8859-15'

This would be a problem if there's more than one translation (for
instance one with polish characters that aren't contained in iso-8859-
15). One could work around this with

if sys.platform in ['cygwin', 'linux2']:
sys.stdout = codecs.EncodedF ile(sys.stdout,
locale.getprefe rredencoding())
sys.stdout.enco ding = locale.getprefe rredencoding()

Funny (more or less): two days work to print "U" and "A" with double
points above.

Thanks to all who have helped to clear my confusion and to bring me
into the right direction for the solution.
Thorsten
Apr 2 '07 #24

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

Similar topics

10
2989
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 Java/JDBC drivers.
0
1256
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 DOMAIN import gettext
10
3731
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 Java/JDBC drivers.
4
1417
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 module B. Each one does this:
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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
9029
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
8897
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
8867
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...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2006
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.