develooper Front page | perl.wxperl.users | Postings from February 2013

Any views on locale handling and wxWidgets > 2.9.0

Thread Next
From:
Mark Dootson
Date:
February 5, 2013 10:44
Subject:
Any views on locale handling and wxWidgets > 2.9.0
Message ID:
5110E25C.7090905@znix.com
Hi All,

As raised in a recent Wx bug ticket, wxWidgets from version 2.9.0 
automatically sets the locale to the users current locale. Formally in 
wxWidgets 2.8.x, the locale by default was 'C'.

The problem arises because in addition to loading gettext translation 
files, the wxWidgets implementation for SetLocale also calls the C 
library setlocale() function. This affects printf, sprintf et al.

A problem therefore arises in that perl makes calls to standard C 
library functions when formatting numbers ( this is regardless of any 
'use locale', or 'no locale' statements. ) Number formatting always uses 
underlying C library functions. The statements 'use locale', or 'no 
locale' make no difference here.

So, if my locale is 'de' then when Wx starts, the C library locale gets 
set accordingly.

my $var = 8.3;
print $var;

will output 8,3 to the terminal. Formatting uses ',' as the fractional 
separator.

Within $var the string representation will be '8,3'

This, whilst possibly correct, isn't what Perl users will be expecting 
at all.

Therefore, I have a fix in SVN code that overrides the automatic setting 
of locale ( by the method suggested in wxWidgets docs ) - so by default 
it remains at LC_ALL = 'C'.

I think wxPerl users would do 99% of I/O via Perl so I don't think 
there's a lot of scope for this approach to cause many problems in the 
wxWidgets libraries.

If you want to set the locale you can do so explicitly.
You can then also reset just the locale for number formatting to 'C' if 
that is what you require as suggested in the original bug post.

use POSIX qw( setlocale, LC_NUMERIC );
.....
setlocale(LC_NUMERIC, 'C');

This code applies equally regardless of which wxWidgets version is being 
used.

Anyone feel strongly that we shouldn't adopt this approach?

Regards

Mark













Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About