From d8158c6c93fc2a83f5acacc7baaf1a840951cf1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 Feb 2021 19:57:31 +0100 Subject: macOS: Be honest about the system locale The system locale of a macOS application is not affected by environment variables like LANG. Yet, we were reporting a name determined from environment variables as the fallbackUiLocale(), rather than one based on the language and country of the actual system locale. This lead, via the usual CLDR likely-subtag fallback, to claiming the system locale's name, language, script and country were those obtained from these environment variables, even when they were at odds with the actual locale being used by the system, which was being used for some queries. Worse yet, any data not supplied by these queries was being obtained from the same CLDR locale as the name, making for an inconsistent mix of locale data. While we cannot avoid the likely-subtag fallback step for fallback data, it is more consistent to use the actual system locale's name as start-point for that fallback. At the same time, add support for the language, script and country queries, so that the QLocale::system() describes itself faithfully, instead of claiming to be the locale that results from that fallback. If we want to support LANG or other environment variable overrides, they should be handled by the layer above the system locale, by changing the default locale of the Qt application, as if the user had called QLocale::setDefault(). [ChangeLog][QtCore][QLocale] QLocale::system() on macOS no longer pretends to support LANG or other environment variables as overrides, as this is not a feature that the system locale on macOS supports. To override the locale of an application, use QLocale::setDefault(), or pass -AppleLocale en_US. Fixes: QTBUG-90971 Change-Id: Ibdaf5ff9a2050f61233a88eabf3c29094f7757f1 Reviewed-by: Volker Hilsheimer Reviewed-by: Edward Welbourne --- tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 60cd4a9a16..83aa5b2c19 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -504,6 +504,7 @@ void tst_QLocale::defaulted_ctor() #if QT_CONFIG(process) static inline bool runSysApp(const QString &binary, + const QStringList &args, const QStringList &env, QString *output, QString *errorMessage) @@ -512,7 +513,7 @@ static inline bool runSysApp(const QString &binary, errorMessage->clear(); QProcess process; process.setEnvironment(env); - process.start(binary, QStringList()); + process.start(binary, args); process.closeWriteChannel(); if (!process.waitForStarted()) { *errorMessage = QLatin1String("Cannot start '") + binary @@ -535,8 +536,12 @@ static inline bool runSysAppTest(const QString &binary, QString *errorMessage) { QString output; + QStringList args; +#ifdef Q_OS_MACOS + args << "-AppleLocale" << requestedLocale; +#endif baseEnv.append(QStringLiteral("LANG=") + requestedLocale); - if (!runSysApp(binary, baseEnv, &output, errorMessage)) + if (!runSysApp(binary, args, baseEnv, &output, errorMessage)) return false; if (output.isEmpty()) { @@ -617,8 +622,13 @@ void tst_QLocale::emptyCtor_data() // Get default locale. QString defaultLoc; QString errorMessage; - if (runSysApp(m_sysapp, cleanEnv, &defaultLoc, &errorMessage)) { -#define ADD_CTOR_TEST(give) QTest::newRow(give) << defaultLoc; + if (runSysApp(m_sysapp, QStringList(), cleanEnv, &defaultLoc, &errorMessage)) { +#if defined(Q_OS_MACOS) + QString localeForInvalidLocale = "C"; +#else + QString localeForInvalidLocale = defaultLoc; +#endif +#define ADD_CTOR_TEST(give) QTest::newRow(give) << localeForInvalidLocale; ADD_CTOR_TEST("en/"); ADD_CTOR_TEST("asdfghj"); ADD_CTOR_TEST("123456"); -- cgit v1.2.3