Discussion:
wxLocale and (wx)setlocale
G H
2006-07-12 11:51:46 UTC
Permalink
Hello,

I'm using wxWidgets 2.6.3 under Windows 2000. I'm coding a program
that contains localised strings (I'm using wxLocale), but that also
writes configuration files on the disk. I would like to have dots
instead of commas, as decimal separators in these con, whatever locale
is currently set.

The 1st solution would be to create another wxLocale object before
writing the file on the disk, and then, after writing, to create
another wxLocale object with the previous locale. I find it a little
clumsy, as I have to add again the .po catalog. Also, it would make
the wxLocale object more "global", instead of being just in one place
of my program.

The 2nd solution would be to directly use setlocale to save the
currently used locale and to set the C (=standard) locale before
writing, and re-putting the previous locale (returned by the call to
setlocale) after writing the file. I've tried this, but the locale
returned by the first call to setlocale is always the locale of my
system, and is not dependent of the locale I used to create the
wxLocale object (which depends on a config file). Why is it that ?
Using wxSetlocale doesn't change anything.

If I can't find a way to make the 2nd solution work, I'll go for the
first but I'd like to know if someone knows how to solve that.

thanks!

guillaume
Vadim Zeitlin
2006-07-13 09:17:02 UTC
Permalink
On Wed, 12 Jul 2006 13:51:46 +0200 G H <***@gmail.com> wrote:

GH> The 2nd solution would be to directly use setlocale to save the
GH> currently used locale and to set the C (=standard) locale before
GH> writing, and re-putting the previous locale (returned by the call to
GH> setlocale) after writing the file.

This should indeed work.

GH> I've tried this, but the locale returned by the first call to setlocale
GH> is always the locale of my system, and is not dependent of the locale I
GH> used to create the wxLocale object (which depends on a config file).
GH> Why is it that ? Using wxSetlocale doesn't change anything.

What is the locale you use with wxLocale? Maybe setting it failed?

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
G H
2006-07-13 11:38:41 UTC
Permalink
Post by Vadim Zeitlin
GH> The 2nd solution would be to directly use setlocale to save the
GH> currently used locale and to set the C (=standard) locale before
GH> writing, and re-putting the previous locale (returned by the call to
GH> setlocale) after writing the file.
This should indeed work.
Except it doesn't, because wxString::Format puts commas instead of
dots for decimal numbers.
Post by Vadim Zeitlin
GH> I've tried this, but the locale returned by the first call to setlocale
GH> is always the locale of my system, and is not dependent of the locale I
GH> used to create the wxLocale object (which depends on a config file).
GH> Why is it that ? Using wxSetlocale doesn't change anything.
What is the locale you use with wxLocale? Maybe setting it failed?
"en", "fr" or "de". wxLocale works somehow, because the strings are
translated by gettext / _( ), but no matter the locale set (even
"en"), the decimal values created with the wxString::Format function
have a comma instead of a dot.
Vadim Zeitlin
2006-07-13 22:03:52 UTC
Permalink
On Thu, 13 Jul 2006 13:38:41 +0200 G H <***@gmail.com> wrote:

GH> > GH> The 2nd solution would be to directly use setlocale to save the
GH> > GH> currently used locale and to set the C (=standard) locale before
GH> > GH> writing, and re-putting the previous locale (returned by the call to
GH> > GH> setlocale) after writing the file.
GH> >
GH> > This should indeed work.
GH>
GH> Except it doesn't, because wxString::Format puts commas instead of
GH> dots for decimal numbers.

Really no idea, sorry. I'd advise putting a breakpoint on setlocale() (the
standard function) and checking where from and with which arguments it is
called under debugger.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
G H
2006-07-21 17:48:02 UTC
Permalink
OK, it was my fault for that. Instead of doing:

char * current_locale = setlocale(LC_ALL,NULL);

to get the current locale, I was doing:

char * current_locale = setlocale(LCALL,"");

which always returned the system's locale ... All this because the
manpage I've read didn't mention the 1st possibility, until I stumbled
upon that page :
http://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html

So, there is no problem with wxWidgets at all :)

bye

guillaume

Loading...