wxLocale: how to use multiple locales for wxString?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
JOHI
Knows some wx things
Knows some wx things
Posts: 34
Joined: Fri Jul 20, 2018 8:25 pm

wxLocale: how to use multiple locales for wxString?

Post by JOHI »

Hello,

I have an application that needs to use "C" style locale instead of the default locale.
The reason is that for my default loclale PI converts to 3,1415 instead of 3.1415.

So in C (win 32), i use to use the C' locale:

Code: Select all

_locale_t localeC = _create_locale(LC_ALL, "C");
wchar_t buf[255];
_swprintf_l(buf,255,_("%f"),localeC,3.14152);
_free_locale(localeC);

And as expected: i get buf = 3.1415 instead of the default 3,1415 if i do not change the locale.

My question: How does one to this in wxWidgets properly?
I created a wxLocale object m°loc in my APP and used m_loc.Init() to activate the default locale.
So all wxString functions behave according to the current locale.

But if I need a local "locale" in 1 thread and 1 function, how does one do this?

Do I need to add multiple languages to the m_loc object?
Do I need to create multiple wxLocale objects?
How do I select the alternative wxLocale for the wxString::Printf("%g") function?
How do I select the second locale only for the current thread?

Best Regards,
Johi.
Post Reply