Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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

share|improve this answer
    
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. –  zunbeltz Oct 24 '12 at 9:56
2  
@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. –  zunbeltz Oct 24 '12 at 10:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.