# Write a class with language dependent strings

I am unable to make my class strings language dependent using babel. I have the following minimal example:

file test-babel.cls

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{test-babel}[2012/10/22 v0.1]

\DeclareOption{spanish}{%
\AtBeginDocument{%
\renewcommand*\conclusionsname{Conclusiones finales}
}
\AtEndOfClass{\main@language{spanish}}
}

\DeclareOption{english}{%
\AtBeginDocument{%
\renewcommand*\conclusionsname{Final conclussions}
}
\AtEndOfClass{\main@language{english}}
}

\newcommand\conclusionsname{dumyy}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions\relax

\newcommand\print{\conclusionsname}


I use this test tex file:

\documentclass{test-babel}
\usepackage[spanish]{babel}
\begin{document}
\print
\end{document}


The result of compilation is the word dummy, the default value, and not the Spanish translation.

Can someone help me to understand how to use babel while writing a class?

-

The spanish option is not passed to the class, to begin with.

I don't think you really need to have class options for this, however. Here is zunbeltz.cls:

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{zunbeltz}[2012/10/22 v0.1]

\providecommand*{\conclusionsname}{Final conclusions}

\AtBeginDocument{
\@ifpackagewith{babel}{spanish}{%
}{}
\@ifpackagewith{babel}{english}{%
}{}
}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions\relax



and here the test document zunbeltz.tex:

\documentclass{zunbeltz}
\usepackage[english,spanish]{babel}
\begin{document}
\conclusionsname

\selectlanguage{english}
\conclusionsname
\end{document}


You'll get

Conclusiones finales
Final conclusions

-
Thanks. Your example work fine. But when only one language is used in zunbeltz.tex, let's english, then there is an error: ! Package babel Error: You haven't loaded the option spanish yet. – TeXtnik Oct 24 '12 at 9:56
@zunbeltz Compile twice: when you remove a language from a document, the .aux file still keeps track of the preceding LaTeX run when the language was loaded. – egreg Oct 24 '12 at 10:25
Thanks. Never noticed this in normal documments. – TeXtnik Oct 24 '12 at 10:29