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

Re: Any views on locale handling and wxWidgets > 2.9.0

Thread Previous | Thread Next
Tarek Unger
February 5, 2013 17:20
Re: Any views on locale handling and wxWidgets > 2.9.0
Message ID:

i personally think this is a good approach.
A simple "use Wx;" anywhere in the code should *not* change the behavior 
of a complete separate codepart.
As described in the Bug Ticket, this automatism was already breaking a 
application which involved database operations.

On the wx-users group the discussed solution is the same as your patch!topic/wx-users/09Jcs4bCEwE

Is it possible to change the overriding of wxAppTraits::SetLocale() 
within perl?

On the other hand, if you are trying to maintain compatibility with 
vanilla cpp-wxWidgets
i would suggest to document this problem on a prominent place.

Something like this at the bottom of (i assembled some of your 
explanation here):

=head1 Locale Behavior

Beginning with 2.9.0 wxWidgets sets the locale to the current system 
Formally in wxWidgets 2.8.x, the locale by default was 'C'.

The problem arises because in addition to loading gettext translation
files, this affects other C calls like printf, sprintf,...

Perl makes calls to these functions when formatting numbers.
Number formatting always uses underlying C library functions.
The statements 'use locale', or 'no locale' make no difference here.

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

     use Wx;
     print 8.3

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

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

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

     use POSIX qw( setlocale LC_NUMERIC );

     setlocale( LC_NUMERIC, C );

This code applies equally regardless of which wxWidgets version is being



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About