Preserving Language Preferences on a Hugo Website

I have been looking for a way to save the language choice of the visitors of my website, so that it automatically will use that selection again when the visitor returns.
I didn’t find an easy solution, apart from people saying that this has to be implemented by the theme authors. I tried to find a theme where this is implemented, but didn’t find one. So I decided to give it a try myself. Successfully.
Indeed, it is dependent on the theme implementation, but I hope my solution will still help others to adapt the theme they are using.

See: Maintaining Language Preferences on a Hugo Website -