From 034e9b087e9f8dde501c4e3e1a29149d984764b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 18 Apr 2023 13:31:04 +0200 Subject: Darwin: Add debug logging of locale/language key parameters Helps debug future issues in this area. Task-number: QTBUG-104930 Pick-to: 6.5 Change-Id: Ia3f54edfa390190bb1cf3809f0cf72b105993a6a Reviewed-by: Timur Pocheptsov Reviewed-by: Edward Welbourne --- src/corelib/text/qlocale_mac.mm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/corelib/text') diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index f3ca942845..1aafacba33 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -14,6 +14,9 @@ #include #endif +#include +#include + QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; @@ -22,6 +25,39 @@ using namespace Qt::StringLiterals; ** Wrappers for Mac locale system functions */ +Q_LOGGING_CATEGORY(lcLocale, "qt.core.locale") + +static void printLocalizationInformation() +{ + if (!lcLocale().isDebugEnabled()) + return; + + // Trigger initialization of standard user defaults, so that Foundation picks + // up -AppleLanguages and -AppleLocale passed on the command line. + Q_UNUSED(NSUserDefaults.standardUserDefaults); + + auto singleLineDescription = [](NSArray *array) { + NSString *str = [array description]; + str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""]; + return [str stringByReplacingOccurrencesOfString:@" " withString:@""]; + }; + + bool allowMixedLocalizations = [NSBundle.mainBundle.infoDictionary[@"CFBundleAllowMixedLocalizations"] boolValue]; + + NSBundle *foundation = [NSBundle bundleForClass:NSBundle.class]; + qCDebug(lcLocale).nospace() << "Launched with locale \"" << NSLocale.currentLocale.localeIdentifier + << "\" based on user's preferred languages " << singleLineDescription(NSLocale.preferredLanguages) + << ", main bundle localizations " << singleLineDescription(NSBundle.mainBundle.localizations) + << ", and allowing mixed localizations " << allowMixedLocalizations + << "; resulting in main bundle preferred localizations " + << singleLineDescription(NSBundle.mainBundle.preferredLocalizations) + << " and Foundation preferred localizations " + << singleLineDescription(foundation.preferredLocalizations); + qCDebug(lcLocale) << "Reflected by Qt as system locale" + << QLocale::system() << "with UI languges " << QLocale::system().uiLanguages(); +} +Q_COREAPP_STARTUP_FUNCTION(printLocalizationInformation); + static QString getMacLocaleName() { QCFType l = CFLocaleCopyCurrent(); -- cgit v1.2.3