Commit graph

66 commits

Author SHA1 Message Date
Václav Slavík
6d48acb5f3 Add unit tests for wxTranslations language lookup 2024-02-13 18:24:43 +01:00
Vadim Zeitlin
39079cbf23 Return true from AddCatalog() if message ID matches language
When the original messages language matches the language of the locale
being used, these strings can be used directly and so AddCatalog()
should still return true for them but it didn't do it any more after the
changes of 94b1a17aeb (Add AddAvailableCatalog() and use it in
AddStdCatalog(), 2023-09-30).

See #18227.

Closes #24019.

Closes #24037.
2023-11-07 15:11:26 +01:00
Vadim Zeitlin
94b1a17aeb Add AddAvailableCatalog() and use it in AddStdCatalog()
The new function only returns true if the catalog could be really
loaded and not if it is considered not to be needed because the message
ID language (which is typically "en-US") happens to be present in the
preferred UI languages list (which seems to always include "en-US" in at
least Western European MSW).

This allows to distinguish, albeit in a rather awkward (but
backwards-compatible) way between having a translation for the given
language and not needed such translation.

It is still not clear if it is really correct to return "en-US" from the
list of preferred languages even if the user has never intentionally
configured the OS to indicate that English is acceptable, but at least
now we can work around this issue and use AddAvailableCatalog() in
AddStdCatalog() to make sure we only skip loading unversioned wxstd.mo
if the versioned wxstd-x.y.mo file is really found instead of never
doing it, as was the case until now (see #23886).

Also add GetBestAvailableTranslation() helper which seems more useful
than the existing GetBestTranslation() one and is similarly related to
it.

See #18227.
2023-10-02 19:21:48 +02:00
Carlo Bramini
15d7aaaa50 Fix wxLocale::GetInfo() unit test under Cygwin
Use the French date format expected by Cygwin CRT which differs from the
one used by MSVC.

Closes #23782.
2023-08-24 02:25:25 +02:00
Vadim Zeitlin
d2101ca3be Show result of parsing wxLocaleIdent in wxUILocale pseudo test
In addition to showing whether the locale is supported or not, show all
of its components to allow interactively verifying if an identifier is
being parsed correctly.
2023-05-19 01:33:13 +02:00
Vadim Zeitlin
38a0a72b71 Show date format in locale pseudo-test too
In addition to the decimal separator, show the date format for the
current locale too in wxUILocale::ShowSystem pseudo-test to check that
this works as expected.
2023-03-04 23:37:05 +01:00
Vadim Zeitlin
2ca76449bf Fail if environment variables define unknown locale under Unix
Don't always "succeed" in wxUILocale::UseDefault() and, consequently, in
wxLocale::Init(wxLANGUAGE_DEFAULT), under Unix systems, even if the
locale couldn't actually be set, as it can happen if the environment
variables contain a locale which is not supported on the current system,
e.g. a "mixed" locale such as "en_FR", or even a completely invalid
string such as "bloordyblop", which still used to succeed.

For now only fix it for reasonably modern systems with locale_t support,
it could be done even for the ancient ones without it later too if
anybody still cares about them.

Closes #23218.
2023-02-06 00:11:31 +01:00
Vadim Zeitlin
14714856b3 Add wxUILocale::GetSystemLocaleId()
This function replaces the existing GetSystemLocale() as it can
represent the locales that don't have any corresponding wxLanguage
values and for which GetSystemLocale() has no choice but to return
wxLANGUAGE_UNKNOWN.
2023-02-05 16:45:14 +01:00
Vadim Zeitlin
c13b3645a8 Fix wxUILocale::FindLanguageInfo() to work for mixed locales
When looking for the language information, we must recognize the
language independently of the region it is followed by, so en_FR is
still English and fr_DE is still French, even if the full locale is
unknown, but this wasn't the case before.

Fix this by comparing the language part of wxLanguageInfo with just the
language of wxLocaleIdent we're trying to match, instead of comparing it
with its full BCP47 tag, which is never going to match.
2023-02-05 15:51:33 +01:00
Vadim Zeitlin
d6c041e69b Don't assume that wxLocale::Init(wxLANGUAGE_DEFAULT) succeeds
At least under macOS it fails when the system locale is something like
en_DE, for example, as setlocale() doesn't support such locales.

Use wxUILocale::GetSystemLanguage() instead of wxLANGUAGE_DEFAULT.
2023-02-05 15:51:33 +01:00
Vadim Zeitlin
4c23721743 Add a pseudo test to show system locale and language
This can be useful to compare the results of calling
wxUILocale::GetSystemLanguage() and the function with the same name in
wxLocale (which actually corresponds to wxUILocale::GetSystemLocale()).
2023-02-05 15:51:33 +01:00
Vadim Zeitlin
7bbee79ca9 Give more information if wxLocale::Default unit test fails
Show the system language in this case.
2022-12-31 20:32:47 +01:00
Vadim Zeitlin
62620215ed Enable tests using CompareStringsEx() for Wine 7.10+
This function works correctly in the recent Wine versions, see
https://bugs.winehq.org/show_bug.cgi?id=9583
2022-12-04 00:44:09 +01:00
Vadim Zeitlin
4519d8e08a Remove wxUSE_UNICODE checks as they're always true now
Also remove all code guarded by "#if !wxUSE_UNICODE".
2022-10-27 19:43:30 +02:00
Vadim Zeitlin
895dd8424c Avoid harmless -Wunused-variable in unit tests
This warning used to be suppressed in Catch headers, but this is not the
case any longer, so work around it in the tests themselves now.
2022-10-18 18:39:13 +02:00
Vadim Zeitlin
4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
2022-10-18 01:25:25 +02:00
PB
88d526660f Replace wxOVERRIDE and wxNOEXCEPT with override and noexcept
Don't use deprecated macros in wxWidgets itself.
2022-10-15 18:10:45 +02:00
Ulrich Telle
34e9c2d53e
Add test case for locale tag with script part
This test checks that a locale tag that includes an explicit script part (like `sr-Latn-RS`) is correctly parsed and located in the internal language database.
2022-08-18 19:16:54 +02:00
Vadim Zeitlin
0167d56427 Merge branch 'glibc-checks'
Fix build with glibc < 2.12

See #22564.
2022-06-26 22:12:51 +02:00
Vadim Zeitlin
a9d3ef2539 Fix date/time format unit test under FreeBSD
Expect French date/time formats actually used there (at least under
French 13), as they're different from the ones used by glibc under
Linux.
2022-06-23 21:15:58 +01:00
Vadim Zeitlin
d74a4ea30d Add wxCHECK_GLIBC_VERSION() and cleanup glibc version checks
Use this macro where possible and simplify the checks in a couple of
places where it isn't (because we're checking for an exact glibc
version).

No real changes.
2022-06-23 19:01:18 +02:00
Vadim Zeitlin
aedd4ca847 Add a test for wxLocale::IsAvailable(wxLANGUAGE_DEFAULT)
This must always returns true.
2022-06-19 02:13:48 +02:00
Vadim Zeitlin
46f81624c1 Add tests for wxLocaleIdent::FromTag() and FindLanguageInfo()
Add at least trivial tests for this function and FindLanguageInfo()
overload using it to confirm that it works minimally correctly.

See #22252.
2022-04-02 16:45:20 +02:00
utelle
6d6e5cde21 Enhance wxUILocale and wxLocaleIdent
Many improvements and fixes to wxUILocale:

- Add wxUILocale method for retrieving wxLocaleIdent identifier,
  localized names, layout direction.
- Add wxLocaleIdent attributes, getter, and setter for
  platform-dependent tags under Windows: extension, sort order.
- Modify method wxLocaleIdent::FromTag to support not only BCP 47-like
  tags, but also platform-dependent syntax.
- Modify method wxLocaleIdent::GetTag to allow specifying the tag type.
- Update internat sample to better show using wxUILocale.
- Update German and French message catalogs for internat sample (German
  fully translated, French msgIds only).
- Introduced wxUILocaleImplStdC under Windows, because locale "en-US" is
  not equivalent to the C locale.
- Adjust wxLocale class to restore previous wxUILocale in the
  destructor.
- Implement wxLocale::GetInfo method through wxUILocale methods.
- Removed LCID dependency in wxLocale.
- Move the implementation of some static wxUILocale methods from
  intl.cpp to uilocale.cpp.

Co-authored-by: Vadim Zeitlin <vadim@wxwidgets.org>

Closes #2615.
2022-03-28 01:11:40 +02:00
Vadim Zeitlin
3ca3944cff Add a pseudo-test for interactive wxUILocale::FromTag() testing
This allows to easily check whether the given locale is supported.
2021-09-05 00:10:05 +01:00
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
5233014a71 Add missing CHECK() to wxUILocale test case for MSW/Mac
Don't forget to check that the locale is actually supported, as
expected, under these platforms.
2021-09-05 00:15:39 +02:00
Vadim Zeitlin
b306cfba26 Disable non-trivial CompareStrings() tests in ANSI build
UTF-8 strings can't be used in this case and we don't care enough about
this deprecated build to bother with using Latin-1 just for it.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
b14137a355 Skip tests using unsupported locales under Unix systems
At least under Linux it's common not to have all the supported locales
installed, so check that a locale is available to avoid test failures if
it isn't.

We still rely on all the locales we use being available under MSW and
macOS, as this should be always the case.
2021-09-01 18:11:40 +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
babcd16bc4 Disable CompareStrings() tests failing under Wine
There isn't much we can do about it, although perhaps these tests could
be re-enabled once https://bugs.winehq.org/show_bug.cgi?id=9583 is
fixed.
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
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
Vadim Zeitlin
59e4e098b7 Add minimal tests for wxUILocale::CompareStrings()
Test the new function in a couple of different locales.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
abdf251b42 Convert intltest.cpp to UTF-8 encoding
Don't use Latin-1 for this file, this encoding is obsolete.

No real changes, the only non-ASCII character in this file was in a
comment anyhow.
2021-09-01 18:11:39 +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
Vadim Zeitlin
b8f63fc7c5 Skip wxLocale wxLANGUAGE_DEFAULT test in ANSI builds
The test fails there, but we don't really care about it, Unicode is
required for any level of acceptable locale support anyhow.
2021-03-01 00:22:39 +01:00
Vadim Zeitlin
5fd85d422f Add a trivial test for setting default locale
Initializing wxLocale using wxLANGUAGE_DEFAULT should work, unless
LC_ALL is explicitly set to an invalid value.
2021-02-28 01:07:47 +01:00
Vadim Zeitlin
fec33079ed Relax French date/time locale unit test to ignore trailing "%Z"
The version of glibc used under Ubuntu 20.04 doesn't have "%Z" in the
French date-time locale, which broke the test there.

Instead of adding even more tests for glibc version, just ignore "%Z" if
it's present, we don't really care about it, we just want to check that
wxLocale::GetInfo() returns something recognizably different from C and
English locale here.
2020-10-19 21:14:27 +02:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Maarten Bent
57180d68c8 Add wxOVERRIDE to test files
And cleanup some tailing spaces and tabs.
2018-07-29 12:08:53 +02:00
Vadim Zeitlin
2ad2bccf33 Don't call static wxLocale::GetInfo() via an object
This is just confusing and unnecessary.

No real changes.
2017-12-10 03:28:18 +01:00
Vadim Zeitlin
9036b3dba8 Remove "C" locale date and time formats test
This test didn't make sense at all as it didn't actually test "C" locale
formats as calling setlocale(LC_ALL, "C") didn't actually change the
values returned by wxLocale::GetInfo(), so it still returned the values
corresponding to the French locale set in this test setUp() method and
the test only passed because it used wrong values (i.e. the same ones as
in French locale test).

We also don't have any simple way to test "C" locale formats, we can
only test them for wxLANGUAGE_DEFAULT, but this corresponds to the OS
defaults which can be customized by user (e.g. in the control panel
under MSW) and so we can't expect them to be equal to any fixed values.

The simplest solution is to just drop this test, as it's not very useful
anyhow (French locale test above already covers the same code).
2017-12-10 03:24:47 +01:00
Vadim Zeitlin
e97c020285 Fix wxLocale::GetInfo() test for French locale under macOS 10.12
The date and time format has changed since 10.10 and now contains an extra
" à " in its middle, so adjust the test to deal with this.
2017-12-09 19:04:52 -07:00
Dimitri Schoolwerth
8f8d58d193 Use wx-prefixed macros throughout the repository.
Change {DECLARE,IMPLEMENT}_*CLASS and {DECLARE,BEGIN,END}_EVENT_TABLE
occurrences to use the wx-prefixed version of the macros.
2015-04-23 22:00:35 +04:00
Vadim Zeitlin
3f66f6a5b3 Remove all lines containing cvs/svn "$Id$" keyword.
This keyword is not expanded by Git which means it's not replaced with the
correct revision value in the releases made using git-based scripts and it's
confusing to have lines with unexpanded "$Id$" in the released files. As
expanding them with Git is not that simple (it could be done with git archive
and export-subst attribute) and there are not many benefits in having them in
the first place, just remove all these lines.

If nothing else, this will make an eventual transition to Git simpler.

Closes #14487.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-07-26 16:02:46 +00:00
Vadim Zeitlin
700256bbdb Correctly restore the originally used C locale in wxLocale dtor.
Save the original locale used before we changed it instead of "restoring" the
same locate that this wxLocale object was using.

Add a unit test to verify that this does work as expected.

Closes #14873.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74426 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-07-06 22:48:20 +00:00
Vadim Zeitlin
9362d82351 Fix unit test French locate checks for glibc >= 2.8.
Until 2.7 glibc wrongly used periods instead of slashes as separators for the
French date format and the test accounted for this, breaking it with recent
glibc versions in which this bug was fixed.

Fix this by limiting the workaround to the old glibc versions only.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70629 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2012-02-20 10:59:37 +00:00