You could probably do this via a script assigned to a keyboard shortcut.
If I were trying to do this, I'd do it in four steps:
Use AppleScript to send the key presses ⌘⇧← then ⌘X to select the current line and cut the text to the pasteboard.
Use a custom script to replace the characters in the cut text with the characters on the same keys when the target keyboard layout is selected, e.g. going from an English layout to a German one, that would mean replacing "y" with "z" and ";" with "ö".
Paste the altered text (also using AppleScript).
Use this script to switch to the desired input source.
For use outside Alfred, I guess you'd want to skip the ⌘⇧← bit and select the text yourself.