# What is the proper way to implement language options in a multilanguage package?

I'm writing a multilingual LaTeX2e package to be used with pdflatex containing several macro and environment definitions. The main language of the document--a thesis--is English, Finnish or Swedish. One page of the document contains text in one secondary language, again English, Finnish or Swedish. My problem is in some ways similar to the one here.

I have implemented the choice of the main language as an option of my package, which I then pass on to the babel package using \PassOptionsToPackage. I then process the package options with english as the default. However, specifying a language other than english globally as say \documentclass[finnish]{article} doesn't seem to pass on the chosen language to babel while \usepackage[finnish]{mypackage} does. This is evident from the caption in tables and figures, which are in English and not Finnish, as well as the title of the list of references, which is also in English in the first case.

After digging around I found a solution to my problem (a more elegant one to using flags and then loading babel with the appropriate options) here.

My question is why doesn't \PassOptionsToPackage pass on the option to babel when it is specified in \documentclass? The option isn't passed on when finnish is specified to both \documentclass and \usepackage{mypackage} either. Why? A minimum working package code for mypackage.sty is:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}[2013/09/26 Version 0.01]

\DeclareOption{english}{%
\PassOptionsToPackage{english}{babel}
%  \AtEndOfClass{\main@language{english}}
}
\DeclareOption{finnish}{%
\PassOptionsToPackage{finnish}{babel}%
%  \AtEndOfClass{\main@language{finnish}}
}
\DeclareOption{swedish}{%
\PassOptionsToPackage{swedish}{babel}%
%\AtEndOfClass{\main@language{swedish}
}
\ExecuteOptions{english}% Default package options
\ProcessOptions \relax

\RequirePackage{babel}%
\RequirePackage[latin1]{inputenc}%
\RequirePackage[T1]{fontenc}%

\endinput


A not-so-minimal LaTeX file that shows the caption and reference list heading in the wrong language follows:

% This works when \AtEndOfClass{\main@language{...} is uncommented
% but not with \PassOptionsToPackage{finnish}{babel}.
\documentclass[finnish]{article}
\usepackage{mypackage}

% This works with \PassOptionsToPackage{finnish}{babel} uncommented.
% This causes an error with \AtEndOfClass{\main@language{
%\documentclass{article}
%\usepackage[finnish]{mypackage}

\begin{document}

\section{Johdanto}

Tämän tekstin lähteenä oleva tiedosto on opinnäytteen pohja...

\begin{table}[htb]
\caption{\label{taulukko1} Taulukon kirjaintyypin...}
\vspace{1em}
\centering
\begin{tabular}{|c|l|r|}
\hline \textbf{A} & 1 & $e^{j \omega t}$ \\ \hline
\end{tabular}
\end{table}

\subsection*{Lähdeluettelo}

Viite \cite{bcs} on esimerkki artikkelin esittämisestä lähdeluettelossa.

\begin{thebibliography}{99}

\bibitem{bcs} Bardeen,\ J., Cooper,\ L.\ N. ja Schrieffer,\ J.\ R.
Theory of Superconductivity. \textit{Physical Review,} 1957, vol.\
108, nro~5, s.\ 1175--1204.

\end{thebibliography}

\end{document}

-
Doesn't the babel key main solve it? -- ie, pass main=finnish instead of just finnish. –  Javier Bezos Oct 7 '13 at 13:19
If you want to use this also with Babel 3.8, then the only ways are: (1) avoid executing the english option, or (2) passing the language options to mypackage rather than the class. With Babel 3.9 you can use main=<language> in \DeclareOption{<language>} –  egreg Oct 7 '13 at 13:59
The global option is passed, but before the local options, among which there is english. So english ends up to be the last one. –  egreg Oct 7 '13 at 14:01
Adding main=finnish works, but it generates the warning Unused global option(s): [main=finnish] –  Luis Costa Oct 7 '13 at 14:32
What I meant was to pass it with \PassOptionToPackage. Due to way LaTeX handles options, a global option cannot be the main language if other languages are set as package options. –  Javier Bezos Oct 7 '13 at 14:51

My question is why doesn't \PassOptionsToPackage pass on the option to babel when it is specified in \documentclass?
Shouldn't a global option, finnish here, be passed to to babel loaded by mypackage regardless of whether it is an option of mypackage? –  Luis Costa Oct 7 '13 at 13:01
What puzzles me even more is that when I load babel with the option finnish as \RequirePackage[finnish]{babel} in the above package with \PassOptionsToPackage` active, Finnish isn't activated. Why is this so? –  Luis Costa Oct 7 '13 at 13:32