Configure Keyboard Layout Switching for Sway

A US keyboard layout increases my productivity as a developer, because characters like square brackets, pipe and backslash are easier to type than on a German keyboard. For the occasional German special character I like to use the AltGr key, preferably with the keys where they are already printed on my physical keyboard. From time to time I need to write longer German texts that don’t need a lot of special characters and need Umlauts instead.