Commit Graph

15 Commits

Author SHA1 Message Date
Vadim Zeitlin
2c580c9190 Add wxUILocale::FromTag() helper
This is exactly the same as wxUILocale(wxLocaleIdent::FromTag()) but
shorter.
2021-09-05 01:00:04 +02:00
Vadim Zeitlin
6b26deaddc Replace wxLocaleIdent ctor from language with FromTag()
This static function parses a subset of the language tags described in
BCP 47 (see https://www.rfc-editor.org/rfc/bcp/bcp47.txt).

Use the tag, as specified by this function, rather than the locale
identifiers components under MSW, where this should allow us to use even
locales that can't be described using just language-script-region.
2021-09-05 01:00:04 +02:00
Vadim Zeitlin
a47a885718 Check that locale ID argument of wxUILocale ctor is not empty
Disallow using empty wxLocaleIdent here, GetDefault() can, and should,
be used for the user default locale.
2021-09-05 01:00:04 +02:00
Vadim Zeitlin
be01b0c36a Rename wxLocaleIdent::IsDefault() to IsEmpty()
We don't use empty wxLocaleIdent as default user locale and it doesn't
make much sense to do it, as the default locale is already accessible
via wxUILocale::GetDefault().
2021-09-05 00:15:39 +02:00
Vadim Zeitlin
836f5abc3d Try to improve CompareStrings() documentation
Explain why this function should be used and give an example of how this
function works in different locales.
2021-09-01 18:12:07 +02:00
Vadim Zeitlin
32316af106 Add wxUILocale::IsSupported()
This function can now be implemented relatively straightforwardly
(although it does require an extra check under Mac), so add it, as it
can be generally useful and we're also going to need it for our own
tests in the upcoming commit.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
ae81d9d207 Implement wxUILocale::CompareStrings() for Unix systems
This required changing CompareStrings() to be a method of wxUILocale
object, rather than just as a static function, as we must only allocate
the locale_t object once, and not during each to this function, as this
could make it unusably slow when using it as a comparison function when
sorting a large list of strings.

This is also more efficient under Mac, where we can similarly allocate
NSLocale only once and even marginally more efficient under MSW, where
we don't have to construct the locale string during each call. And,
under all platforms, it also simplifies code by separating this function
implementation from the initialization of wxUILocaleImpl.

Also document that case-insensitive comparison is not available under
Unix and adjust the tests accordingly.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
45f9908e05 Allow creating wxUILocale objects for any locale
Creating such objects (without using them for the UI) is supported under
all platforms, so allow doing it.

Note that this is only supported under Unix systems when locale_t and
related functionality is available, but this should be the case just
about everywhere by now.

Add a test (or, rather, replace an existing test which was disabled by
default) checking that we can now get locale information about any
locale, not necessarily the currently used one.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
592e1678ce Add charset support to wxLocaleIdent and accessors
Charset is important for Unix systems as some locales may not be
available without it, e.g. "xx_XX" may not be supported, but
"xx_XX.utf8" could be.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
20e3697f00 Change wxLocaleIdent ctor to take char* rather than wxString
This is convenient, as it allows using a simple string such as "en" as
an argument to the functions taking wxLocaleIdent and rely on implicit
conversion, whereas previously explicitly writing either wxString("en")
or wxLocaleIdent("en") would be necessary.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
ddd60d5a39 Add link to ISO 639 language codes to the documentation
This can be useful as not all of them are really obvious.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
e27497774a Optionally use case-insensitive comparison in CompareStrings()
Harmonize Mac and MSW versions by using case-sensitive comparison in
both of them by default, but allowing to use a flag to use
case-insensitive comparison instead.
2021-09-01 18:11:40 +02:00
Alexander Koshelev
c8269210a2 Add wxUILocale::CompareStrings() function
This function allows comparing strings using the sort order of the
specified locale, represented by the new wxLocaleIdent class.

It is implemented using CompareStringEx()[1] under MSW and
NSString::compare:options:range:locale:[2] under macOS, generic
implementation for the other platforms is upcoming.

[1]: https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringex
[2]: https://developer.apple.com/documentation/foundation/nsstring/1414561-compare?language=objc
2021-09-01 18:11:33 +02:00
Vadim Zeitlin
8fa853a3e2 Add wxGetUIDateFormat() helper function
Retrieve thr date format to use, even when wxUSE_INTL==0.
2021-08-20 23:37:28 +02:00
Vadim Zeitlin
b9cbe6770f Add wxUILocale with minimal functionality
Use it in the sample to show what (little) it can do right now.
2021-08-20 22:02:46 +02:00