wxApp::Initialize() setting the locale? [wxGTK 2.8.0]

Ian Britten britten at caris.com
Tue Mar 6 08:09:51 PST 2007


Vadim Zeitlin wrote:
> [redirected to wx-dev from wx-users as it seems more appropriate]

[ Sorry - I'm not on wx-dev, and this almost disappeared into my spam...
I'm also not sure if non-subscribers can post to wx-dev... ]

> On Tue, 27 Feb 2007 13:28:36 -0400 Ian Britten <britten at caris.com> wrote:
> 
> IB> After some debugging/digging, I noticed that wxApp::Initialize() (wxGTK)
> IB> explicitely calls gtk_set_locale(), setting the program locale to be
> IB> the same as the users current settings.
> 
>  For the reference, this call was added by Robert 8.5 years ago in revision
> 1.13 of src/gtk/window.cpp with the following commit message:
> 
> Added support for non-european fonts and X extension using gtk_set_locale()
>  
> So apparently it is needed to use i18n with GTK+ at all and so it seems
> like a good idea to have it.

Agreed.  It seems like a good idea, and is consistent with what well
written code should expect/do.  (In an ideal world...)

> IB> Given that large amounts of our code is currently not ready for a
> IB> wholesale locale switch, I'm unsure how to proceed... I can't
> IB> currently support foreign locales, and if the user has switched their
> IB> locale, I know that the app won't work correctly.
> 
>  I do see your point as well though.

Yea.  I'm just starting to play with some localization stuff.

BTW - I'm thrilled with how easy it was to get different languages
into my interface, how easy 'poedit' makes stuff, and was blown away
that the interface correctly 'flipped' when run under an Arabic
Locale!
Also, some coworkers are trying to get a (non-WX) MFC app converted
to French, and are very unhappy about what is involved (Dialog
resizing, .rc files, etc), and are *very* envious about how little
I needed to do with my wx app!  (They're also muttering about
looking closer at using wx!  :)
*** Kudos to wx, and all the developers! ***

Although getting the different languages into the UI was straight
forward, I hit a brick wall since the app wouldn't run (Due to the
code not handling the different locale).
For now, I've started with a small utility, and am working though
fixing the various problems to make it work correctly when the
locale is changed.
However, for a Large app (Encompassing potentially thousands of
classes and a million lines of code), it can't all be 'fixed' at
once (As I'm sure you appreciate!).

For now, it may not be a critical problem for me, as we've never
really supported different locales, and as such, nobody will
likely be trying it too soon (Hopefully...).
However, I think the option to have a different language for the
UI, but NOT changing the locale represents a crutial/tangible
migration step for code like ours, allowing smaller subsystems to
be upgraded/fixed in a controlled manner.

> IB> If I try to work around this (by trying to set the locale back to C),
> IB> how much of the wx subsystem will be left in the 'other' locale?
> IB> Can it be reset/switched?
> 
>  I think this is going to result in problems.

Bummer... :(

> IB> Finally, can anyone clarify the behaviour of wxMSW?  Obviously there's
> IB> no call to gtk_set_locale() in there, but I didn't see anything that
> IB> seems to be setting the locale.  Does this mean that wxMSW behaves
> IB> differently than wxGTK?  (Sorry, I'm not familiar with Windows, and
> IB> don't have a Windows box to test on...)
> 
>  Yes, wxMSW doesn't change the locale and it's indeed an inconsistency
> between ports and so is a bad thing. However my way of solving it would be
> to add setlocale(LC_ALL, "") call to wxMSW startup code somewhere rather
> than removing gtk_set_locale() from wxGTK.
> 
>  But as I wrote above, I realize that some applications may not want to
> change locale at all. So ideally we should provide a possibility to avoid
> this even though I think it should still be done by default. The simplest
> way to allow for it would be to add a virtual wxApp SetLocale() function
> which would be called from OnInit() and could be overridden by the user
> code to do nothing.
> 
>  What do you think?

I think this would be a valuable enhancement, both for unifying the
different ports, and to provide a transition step for legacy code
bases (Like ours!)

You would need to consider how to handle the wxGTK port, given that
it has had this call present for years, and whether to have the
new wxApp::SetLocale() either:
- Do nothing (Thereby changing its current behaviour)
- Set the locale as before (And thus remain different than wxMSW)
[ Bummer of a choice - Glad I don't have to decide!  ;) ]

If you are able to do something like this, do you know what version
it would be available in?  2.8.1?  2.8.2?  2.9.x?  Other?

Thanks for any help/changes!
Ian




More information about the wx-dev mailing list