Since Catalina, macOS has provided for automatic localization of key equivalents as described here: https://developer.apple.com/documentation/swiftui/keyequivalent. If you set the keyboard shortcut to cmd-{, then it will become cmd-shift-ö on a German AZERTZ layout.
The framework even handles display of shortcuts so that they render correctly if you bind them to Button
s in the menu:
- the Safari menu with a US QWERTY keyboard
- the Safari menu with a DE QWERTZ keyboard
I’d like to be able to render the shortcut in our own UI, but I cannot find an API to query this information.
If you create a menu item and then render it to the screen, you can read the keyEquivalent
property and it returns the localized value. Unfortunately if you read the keyEquivalent
property immediately after writing it, then it does not get localized. I am not sure how that process works either.