From 5f15a93f16727824372bfd1a6490754440de942f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 Jan 2024 15:11:10 +0100 Subject: macOS: Add helper function for getting AppKit localized strings If we for some reason can't look up AppKit, or if the table or string within that table is not found we will end up using the key as is. Pick-to: 6.7 Change-Id: I5d574288e421e586458266899ffdff90eeadec8f Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/cocoa/qcocoahelpers.h | 3 +++ src/plugins/platforms/cocoa/qcocoahelpers.mm | 9 +++++++++ src/plugins/platforms/cocoa/qcocoamenubar.mm | 3 +-- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 0fcda72b4d..c6862a9e65 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -78,6 +78,9 @@ Qt::MouseButtons currentlyPressedMouseButtons(); // accelerators. QString qt_mac_removeAmpersandEscapes(QString s); +// Similar to __NXKitString for localized AppKit strings +NSString *qt_mac_AppKitString(NSString *table, NSString *key); + enum { QtCocoaEventSubTypeWakeup = SHRT_MAX, QtCocoaEventSubTypePostMessage = SHRT_MAX-1 diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index ec64c94d0b..1eba88d5e3 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -336,6 +336,15 @@ QString qt_mac_removeAmpersandEscapes(QString s) return QPlatformTheme::removeMnemonics(s).trimmed(); } +NSString *qt_mac_AppKitString(NSString *table, NSString *key) +{ + static const NSBundle *appKit = [NSBundle bundleForClass:NSApplication.class]; + if (!appKit) + return key; + + return [appKit localizedStringForKey:key value:nil table:table]; +} + QT_END_NAMESPACE /*! \internal diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 72bbd9498d..78e1a399c2 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -204,8 +204,7 @@ void QCocoaMenuBar::syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate) // and document that the user needs to ensure their application matches // this translation. if ([menuTitle isEqual:@"Edit"] || [menuTitle isEqual:tr("Edit").toNSString()]) { - static const NSBundle *appKit = [NSBundle bundleForClass:NSApplication.class]; - menuItem.title = [appKit localizedStringForKey:@"Edit" value:menuTitle table:@"InputManager"]; + menuItem.title = qt_mac_AppKitString(@"InputManager", @"Edit"); } else { // The Edit menu is the only case we know of so far, but to be on // the safe side we always sync the menu title. -- cgit v1.2.3