I18n issue with optik

Thorsten Kampe thorsten at thorstenkampe.de
Mon Apr 2 14:06:49 EDT 2007


* 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



More information about the Python-list mailing list