I18n issue with optik

T

Thorsten Kampe

* 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.EncodedFile(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
 
D

Damjan

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).
 
T

Thorsten Kampe

* 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 internationalization, 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.EncodedFile(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.EncodedFile(sys.stdout, 'iso-8859-15')
sys.stdout.encoding = '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.EncodedFile(sys.stdout, 'iso-8859-15')
sys.stdout.encoding = '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.EncodedFile(sys.stdout,
locale.getpreferredencoding())
sys.stdout.encoding = locale.getpreferredencoding()

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top