diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-17 17:40:59 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-01 16:38:32 +0200 |
commit | 212f925c26d27ef3e3e94e4fddff8cae726a156e (patch) | |
tree | f9380cb1f98ba9e0600eae10b28e8f42c93b362e /tests | |
parent | 0c0642ee0932d6f6a33dca31c3fb2a4ab9f41282 (diff) |
Work round macOS's omission of en_DE from its own uiLanguages()
When the system locale is en_DE, macOS seems to think we should use
en_GB as the right translation. While that probably is a sensible
choice in the absence of an en_DE translation, we should definitely
use the en_DE translation if available, especially if en_GB isn't
available (which lead to a fall-back to de_DE, given later entries in
macOS's list). So prepend the system locale's own pcp47Name() if it
(isn't the C locale and) is missing from what we would otherwise have
used for uiLanguages(), after likely sub-tag perturbations.
Add a test simulating (some approximation to) what macOS was doing
that would have caught this case; and add a scope-guard reporter to
the test to report what shows up when lists don't match.
Conflicts resolved: 6.4 has a fix for a related issue, that means the
last two languages in the new test-case are swapped. Qt 6 has richer
infrastructure in QLocaleId that's missing in 5.15, so I had to port
the uses of it to the facilities present in 5.15.
Fixes: QTBUG-104930
Change-Id: I116234708067e1717d9157aebc84da76e04a9f38
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 753bfdf6a1336cc296e5fc8175aedd000c2cc013)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 84901f8f75..4ee6c6df75 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -3012,7 +3012,12 @@ public: QVariant query(QueryType type, QVariant /*in*/) const override { - return type == UILanguages ? QVariant(QStringList{m_name}) : QVariant(); + if (type == UILanguages) { + if (m_name == u"en-DE") // QTBUG-104930: simulate macOS's list not including m_name. + return QVariant(QStringList{QStringLiteral("en-GB"), QStringLiteral("de-DE")}); + return QVariant(QStringList{m_name}); + } + return QVariant(); } QLocale fallbackUiLocale() const override @@ -3038,6 +3043,12 @@ void tst_QLocale::systemLocale_data() QTest::addRow("ukrainian") << QString("uk") << QLocale::Ukrainian << QStringList{QStringLiteral("uk"), QStringLiteral("uk-UA"), QStringLiteral("uk-Cyrl-UA")}; + QTest::addRow("english-germany") + << QString("en-DE") << QLocale::English + // First two were missed out before fix to QTBUG-104930: + << QStringList{QStringLiteral("en-DE"), QStringLiteral("en-Latn-DE"), + QStringLiteral("en-GB"), QStringLiteral("en-Latn-GB"), + QStringLiteral("de-DE"), QStringLiteral("de"), QStringLiteral("de-Latn-DE")}; QTest::addRow("german") << QString("de") << QLocale::German << QStringList{QStringLiteral("de"), QStringLiteral("de-DE"), QStringLiteral("de-Latn-DE")}; @@ -3062,7 +3073,11 @@ void tst_QLocale::systemLocale() MySystemLocale sLocale(name); QCOMPARE(QLocale().language(), language); QCOMPARE(QLocale::system().language(), language); + auto reporter = qScopeGuard([]() { + qDebug("\n\t%s", qPrintable(QLocale::system().uiLanguages().join(u"\n\t"))); + }); QCOMPARE(QLocale::system().uiLanguages(), uiLanguages); + reporter.dismiss(); } QCOMPARE(QLocale(), originalLocale); |