# Hyperref uses wrong from multiple language options

I want to write my master's thesis with the template I found here. Everthing worked fine, until I wanted to write and reference an algorithm written with algorithm2e.

As I have to write a German abstract for my English thesis I declare that in the documentclass command, but this has the effect, that the hyperref references generated via \autoref (as well as the algorithm itself) get the German labels.

I condensed the problem to the following MWE.

Here the actual tex document:

\documentclass[ngerman,english]{exampleStyle}

%\selectlanguage{english}
\usepackage[
onelanguage % added for test purposes
]{algorithm2e}
%\renewcommand{\algorithmcfname}{Algorithm}

\begin{document}
%\selectlanguage{english}
\begin{algorithm}
\LinesNumbered
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\Input{some input}
\Output{some output}
Just some random line\;\nllabel{algoLine:someLine}
\While{condition}{action\;}
\caption{Some Algorithm}
\label{algo:someAlgo}
\end{algorithm}

%\selectlanguage{english}
Some reference to the algo: \autoref{algo:someAlgo}\\
Some reference to a line: \autoref{algoLine:someLine}

\end{document}


And here the referenced style file (exampleStyle.sty):

\ProvidesClass{exampleStyle}

\RequirePackage{babel}
\RequirePackage{hyperref}


So the question is: How do I get the autoref command to use the English labels instead of the German ones while still keeping the ngerman parameter? I hope there is a way to do this without renaming all cfnames, as I find that kind of ugly.

Your exampleStyle.sty should be an exampleClass.cls.

Beside this: Setting languages through the global option of \documentclass is rather a pain as you don't have much control how the packages that receive the list handle the languages and so e.g. can't really avoid that one package sees a language that is should ignore.

In the case of algorithm2e you have the additional problem that the package uses \ProcessOptions instead of \ProcessOptions* to handle the package options, which means that languages are processed in the order they are declared in the package and not in the order you pass them to the package.

So it is better to avoid the option list of \documentclass and pass the options only to the babel package:

\PassOptionsToPackage{ngerman,english}{babel}
\documentclass[]{exampleStyle}

\usepackage{algorithm2e} %english is default

\begin{document}

\begin{algorithm}
\LinesNumbered
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\Input{some input}
\Output{some output}
Just some random line\;\nllabel{algoLine:someLine}
\While{condition}{action\;}
\caption{Some Algorithm}
\label{algo:someAlgo}
\end{algorithm}

Some reference to the algo: \autoref{algo:someAlgo}\\
Some reference to a line: \autoref{algoLine:someLine}

\end{document}