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