Hello,
This is continuation of the discussion which started at
https://github.com/wxWidgets/wxWidgets/pull/2124 where I previously wrote:
VZ> IMO the ideal behaviour should really be:
VZ>
VZ> 1. Use C (i.e. US) locale everywhere if wxLocale is not used at all.
VZ> 2. Use user locale if wxLocale(wxLANGUAGE_DEFAULT) is used.
VZ>
VZ> I think (2) should mostly work (except for the really bad problem
VZ> described in this ticket[*] that I'd very much appreciate your feedback on
VZ> too) and this tries to fix/improve things for (1).
VZ>
VZ> [*]:
https://trac.wxwidgets.org/ticket/19023
and Stefan replied:
SC> I think we have to dive into these a litte bit more to make sure the
SC> cure is not worse than the problem
SC>
SC> 1. Right now wx under macOS is using the current CFLocale which is
SC> determined by the OS, so dateformats etc. are correct. Without
SC> setting a locale, not a c-level nor at wx level.
SC> Changing this now would suddenly change the behaviour of existing
SC> apps on macOS, eg Dates would be displayed differently ...
Clearly, there is a disagreement about what our goal should be in the
first place. I always thought that an internationalized wx application
would have to perform wxLocale::Init(wxLANGUAGE_DEFAULT) during its
initialization and that applications not doing this should be isolated from
the current user locale as much as possible. IOW, if you do _not_ use
wxLocale, then the application should get numbers entered by user using the
decimal point, whatever is the current locale. And I still believe that
it's not an unreasonable expectation and that changing this will (subtly)
break the existing code, e.g. using wxSpinCtrl::SetValue("1.234") would
stop working in German (or French, or ...) locale. Of course, this never
was the best thing to do, but AFAIK it does work right now and the string
typically is not hardcoded in the sources, but comes from a file, so it's
not that obvious to find and correct all the places where this happens.
<aside>
Floating point numbers are not used much in wx API, and so maybe we could
modify SetValue() and other places to accept numbers using either the point
or the comma, but this seems a wrong thing to do and wouldn't work in the
other direction anyhow, so I don't think we should consider this.
</aside>
So in my vision of how things should work, everything should really use
C/US locale by default and only by using wxLocale::Init() would you opt
into locale-specific behaviour. Of course, IMO most applications should use
wxLocale in any case, so the case of not using it is not even very
interesting, but I'd still prefer to avoid returning strings using decimal
comma to the applications that don't want to do anything with the locales.
Especially because if we do it like this, the only way to avoid it would be
to explicitly use wxLocale(wxLANGUAGE_ENGLISH_US) which is something we've
never recommended doing before, while fixing the problem with wrong (i.e.
non-localized) dates display would require just using wxLANGUAGE_DEFAULT
which is something that was recommended since always.
Stefan, do my arguments seem convincing to you? What about the others? I'd
really like to understand what do we want to achieve before trying to
actually do it, I think it would significantly increase our chances of
success :-)
On a more technical level, Stefan also wrote:
SC> 2. Setting a locale eg to de_CH is not working correctly at the
SC> c-level as I wrote, it only knows about de, the decimal and
SC> thousands separators are wrong.
This really looks like a bug in macOS :-( The same
$ LC_ALL=de_CH printf "%g\n" 1.234
command outputs "1,234" under macOS 11.1 while it correctly outputs "1.234"
under Linux. And /usr/share/locale/de_CH/LC_NUMERIC under macOS is just a
symlink to ../de_DE.UTF-8/LC_NUMERIC which, of course, explains why it
behaves like this but doesn't help.
SC> So there I'd like to leave LC_NUMERIC at C and perform the inverse
SC> of what FromDouble/FromCDouble etc are doing at wxString level.
SC>
SC> So in summary IMHO we will never be able to depend on C-Level locale on
SC> macOS, we will have to use the CFLocale information and perform
SC> replacements like mentioned in 2)
The problem with this is that there is a lot of existing code using
[sf]printf() and other C functions (and whatever you may think of these
functions, even using C++ locale support wouldn't help with the problem
above). If we don't interoperate with this code, we're going to have
problems without any simple solution. E.g. just consider a typical GUI
application that gets string from wx and then uses some non-GUI library for
doing something with them. How are you going to fix things to work in both
de_DE and de_CH locales if wx strings use a decimal point in the latter but
comma in the former while the non-GUI library simply has no way to use
different values in the 2 cases without using non-portable code because
either it assumes C locale (and then it doesn't work in de_DE) or it uses
the current locale (and then it doesn't work in de_CH).
Also, if we leave LC_NUMERIC (and why not LC_TIME too?) at C, what is the
point of changing LC_ALL at all? Which locale facet do we really need to
change, in fact? We already have wxCmpNatural() that should be used rather
than relying on LC_COLLATE. Nothing that we do uses LC_MONETARY, AFAIK.
LC_CTYPE doesn't really make sense with Unicode anyhow. And we have
wxTranslations rather than relying on LC_MESSAGES. So AFAICS your proposal
is basically equivalent to not setting C locale at all under macOS.
And while I'm not saying that we shouldn't do this, I do have a feeling
that this is not the right thing to do, especially if we only decide to do
it because of the problem with de_CH (even if I know that it's a
subjectively important locale...). Is there really no chance of Apple
fixing their locale definition instead?
To summarize, there are 2 questions I'd like to answer before changing
anything:
1. What should applications not using wxLocale at all expect from wx?
Here it seems obvious that the C locale must not be changed (as this
would silently breaks tons of code), but what should happen with the
UI, i.e. should it use locale-specific or the US formats for
dates/numbers?
2. What should applications using wxLocale(wxLANGUAGE_DEFAULT) expect?
Here it seems pretty clear that the dates/numbers should appear in the
appropriate locale-specific format in the UI, but it's not clear how
should the standard C functions work.
Thanks in advance!
VZ