Greetings,
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 a database connections.
On the wx-users group the discussed solution is the same as your patch
https://groups.google.com/forum/?fromgroups#!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 Wx.pm (i assembled some of your
explanation here):
=head1 Locale Behavior
Beginning with 2.9.0 wxWidgets sets the locale to the current system
locale.
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
separator.
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
used.
---
Regards
Tarek
Am 05.02.2013 11:43, schrieb Mark Dootson:
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