Creating bilingual Beamer slides

For a lecture on Python I have been looking for a way to create bilingual slides in a single document. Based on https://tex.stackexchange.com/questions/443714/bilingual-slides-beamer-comment-package-and-non-ascii-characters-umlauts-dia and https://tex.stackexchange.com/questions/203412/using-a-generic-way-to-evaluate-global-document-options I have compiled the following example.

One simply needs to set the babel language in the document options to switch between German and English.

\documentclass[ngerman]{beamer}
 
\usepackage{comment}
\makeatletter
\newif\if@ngerman
\newif\if@option@ngerman
\DeclareOption{ngerman}{%
	\@ngermantrue
	\@option@ngermantrue
}
\ProcessOptions*\relax
\newcommand*{\ifngerman}{%
	\if@ngerman
	\expandafter\@firstoftwo
	\else
	\expandafter\@secondoftwo
	\fi
}
\makeatother
 
\ifngerman{
\usepackage[main=ngerman]{babel}
\includecomment{DE}
\excludecomment{EN}
}{
\usepackage[main=english]{babel}
\includecomment{EN}
\excludecomment{DE}
}
 
\begin{document}
	\begin{DE}
		\begin{frame}[fragile]{Hallo Welt}
		Hallo Welt
	\end{frame}
\end{DE}
 
\begin{EN}
	\begin{frame}[fragile]{Hello World}
	Hello World
\end{frame}
\end{EN}
 
\end{document}

Photo by Alex Litvin on Unsplash