[Tex/LaTex] Write a class with language dependent strings

babeldocumentclass-writing

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

\LoadClass{report}
\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?

Best Answer

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}{%
    \addto\captionsspanish{\renewcommand*\conclusionsname{Conclusiones finales}}%
  }{}
  \@ifpackagewith{babel}{english}{%
    \addto\captionsenglish{\renewcommand*\conclusionsname{Final conclusions}}%
  }{}
}


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

\LoadClass{report}

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

Related Question