The method to change the name of the contents while using the babel package
is described here.

Per the answer included in the link, the following code may be used:

\documentclass{article}

\usepackage[american]{babel}

\renewcommand{\contentsname}%
{newContentsName}%
}

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}

\end{document}


If I wanted to use a variable for the language, I thought I could make the following adjustment:

\documentclass{article}

\newcommand{\xLanguage}{american}          % <-- Added this command

\usepackage[\xLanguage]{babel}             % <-- Implemented here

\renewcommand{\contentsname}%
{newContentsName}%
}

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}

\end{document}


But this does not work.
Am I approaching this correctly?

\csname captions\xLanguage\encsname must be expanded first, before \addto can work with the 'real' command sequence name, i.e. an \expandafter is needed before \addto.

I.e. captions\xLanguage must be expanded first to yield the content of \xLanguage, american in the O.P. example, such that captionsamerican is usable for \csname ...\endcsname.

Only after that \addto\captionsamerican{...} is finally available.


\documentclass{article}

\newcommand{\xLanguage}{ngerman}          % <-- Added this command

\usepackage[\xLanguage]{babel}             % <-- Implemented here

\renewcommand{\contentsname}%
{Verzeichnisse der tollen Inhalte}%
}

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}

\end{document}


I'm not sure about the usefulness of this approach, but you can use etoolbox:

\documentclass{article}
\usepackage{etoolbox}

\newcommand{\xLanguage}{american}          % <-- Added this command

\usepackage[\xLanguage]{babel}             % <-- Implemented here

\csappto{captions\xLanguage}{% <-- and here
\renewcommand{\contentsname}%
{newContentsName}%
}

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}

\end{document}
`

• Alternatives informative and are always appreciated. – kando Aug 22 '16 at 22:39