summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_mac.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-04-18 13:31:04 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-04-24 14:24:51 +0200
commit034e9b087e9f8dde501c4e3e1a29149d984764b6 (patch)
treecce508fb9dd483cf9a426b24c677863bb2001c93 /src/corelib/text/qlocale_mac.mm
parentf3c10280f59d35fbf0862e6e353602e7aa8ef901 (diff)
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 <timur.pocheptsov@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qlocale_mac.mm')
-rw-r--r--src/corelib/text/qlocale_mac.mm36
1 files changed, 36 insertions, 0 deletions
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 <CoreFoundation/CoreFoundation.h>
#endif
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/qcoreapplication.h>
+
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<CFLocaleRef> l = CFLocaleCopyCurrent();