[Tex/LaTex] Multiple languages in beamer LaTeX

beamerlanguages

I want to create a LaTeX beamer presentation within multiple languages in the following sense:
The sorce code should contain the different languages, but the language of the compiled result should depend on a specific choice of one language.

A solution has already been provided https://tex.stackexchange.com/a/31401/21166. However the \sectionlang command seems to have problems, when using beamer LaTeX with \input.
There is no error displayed, but the command are ignored during compilation.

Everyting works fine in the following code example (the package multilanguage is from the link above)

\documentclass{beamer}
\usepackage[ngerman,english]{babel}
\usepackage{ifthen}
\usepackage{multilanguage}

\setdoclang{en}{english}
% \setdoclang{de}{ngerman}

\begin{document}
\frame{
       \tableofcontents
      }

\sectionlang{en}{Section 1}
\sectionlang{de}{Abschnitt 1}

\frame{
       \lang{de}{Folie 1}
       \lang{en}{Slide 1}
      }

%\mode<all>
%\input{./frame.tex}
%\mode*
%\againframe<1>{slide2}

\sectionlang{en}{Section 2}
\sectionlang{de}{Abschnitt 2}

\frame{
      \lang{en}{Slide 3}
      \lang{de}{Folie 3}
     }

\end{document}

The frame.tex file contains

\frame<0>[label=slide2]
    {\frametitle{\lang{de}{Folie 2}
         \lang{en}{Slide 2}}
     \lang{de}{Folie 2}
     \lang{en}{Slide 2}
    }

However, when the \input block in uncommented, the compiled ToC does not contain Section 2 anymore.

Best Answer

Update:

I think the best way would be to build two tex files, one for each needed language. Then the TOC, hyphenation and so on are working as usual. Of course the disadvantage is that you have to change two (or more) files, depending on the number of used languages.

An alternative way could be to use package ifthenelse, define boolean variables for the used languages and include each frame in a construct like:

\setboolean{MWEenglish}{true} % sets variable MWEenglish on true
\ifthenelse{\boolean{MWEenglish}}{% 
  % Then frame definition here
}{% 
  % Else part here (two language: frame in second language)
} % end ifthenelse

That should help you to keep all languages in one file.

Old answer:

Just to give you a hint how to procede please have a look on the following MWE. The package filecontents is used to write a changed package file multilanguage.sty.

I have added the line \newcommand{\frametitlelang}[2]{\lang{#1}{\frametitle{#2}}} to have a new macro \frametitlelang. This macro is used to build the frame title depending on the language.

\RequirePackage{filecontents}
% writes file multilanguage.sty
\begin{filecontents*}
\newcommand{\setdoclang}[2]
{
    \main@language{#2}
    \def\doclang{#2}
    \def\doclangshort{#1}
}

\setdoclang{en}{english}

%
% Multilingual support commands
%
\newcommand{\langif}[3]
{
    \ifthenelse{\equal{#1}{\doclang} \or \equal{#1}{\doclangshort}}
        {#2}
        {#3}%
}
\newcommand{\lang}[2]{\langif{#1}{#2}{}}
\newcommand{\sectionlang}[2]{\lang{#1}{\section{#2}}}
\newcommand{\subsectionlang}[2]{\lang{#1}{\subsection{#2}}}
\newcommand{\subsubsectionlang}[2]{\lang{#1}{\subsubsection{#2}}}
\newcommand{\frametitlelang}[2]{\lang{#1}{\frametitle{#2}}}       % new macro
\end{filecontents*}

\documentclass{beamer}
\usepackage[ngerman,english]{babel}
\usepackage{ifthen}
\usepackage{multilanguage}

%\setdoclang{en}{english}
\setdoclang{de}{ngerman}

\begin{document}
\frame{
       \tableofcontents
      }

\sectionlang{en}{Section 1}
\sectionlang{de}{Abschnitt 1}

\frame{
       \lang{de}{Folie 1}
       \lang{en}{Slide 1}
      }

\mode<all>
%\input{./frame.tex}  %following is included frame.tex
\frame<0>[label=slide2]
    {\frametitlelang{de}{Folie 2}     % new macro
     \frametitlelang{en}{Slide 2}     % new macro
 %   }
     \lang{de}{Folie 2}
     \lang{en}{Slide 2}
    }
\mode*
\againframe<1>{slide2}

\sectionlang{en}{Section 2}
\sectionlang{de}{Abschnitt 2}

\frame{
      \lang{en}{Slide 3}
      \lang{de}{Folie 3}
     }

\end{document}