3

I'm currently adding a feature to my own class file: automatic translation of the footer according the main language that has been defined in my document.

\DeclareTranslationFallback{pageOfPages}
{\pagename~\thepage~of~\pageref{lastPage}}
\DeclareTranslation{English}{pageOfPages}
{\pagename~\thepage~of~\pageref{lastPage}}
\DeclareTranslation{Dutch}{pageOfPages}
{\dutchpagename~\thepage~op~\pageref{lastPage}}
\DeclareTranslation{French}{page-of-pages}
{\frenchpagename~\thepage~de~\pageref{lastPage}}

As you can see, the translations are handled by the translations package and the language management by babel. I'm using XeTeX, but my class aims at being rendering engine agnostic.

I'm trying to get the translated content of \pagename. \pagename contains the text used to represent the page which is "page" by default. By default, English is used. If we want the translated version, if babel is used, the latter prefixes the command by the language name e.g.: \frenchpagename for French (see here for details). While this is true for French, the situation cannot be verified with \englishpagename nor with \dutchpagename. I checked the frenchb babel config and could not find a specific \frenchpagename command. It's seems the latter is defined in babel internals not in language specific files.

So my question, how am I supposed to get the \pagename version for Dutch or any other language? I even tried to access babel internals (makeatletter, etc.) with no success.

Minimum working example:

\documentclass{report}

\usepackage[french]{babel}
\usepackage{translations}

\DeclareTranslationFallback{pageOfPages}
{\frenchpagename~\thepage~of~\pageref{lastPage}}
\DeclareTranslation{English}{pageOfPages}
{\frenchpagename~\thepage~of~\pageref{lastPage}}
\DeclareTranslation{Dutch}{pageOfPages}
{\dutchpagename~\thepage~op~\pageref{lastPage}}
\DeclareTranslation{French}{page-of-pages}
{\frenchpagename~\thepage~de~\pageref{lastPage}}

\begin{document}

\GetTranslation{pageOfPages}

\label{lastPage}
\end{document}

Change french to english for example.

EDIT: The main problem arises when I specify [base] in babel options without specifying a main language, LaTeX complains in that case he cannot find the \pagename statement. The idea is to check if a main language has been defined in babel first, otherwise we need to define it to properly fallback to English.

Thanks for your help.

3
  • related: tex.stackexchange.com/questions/116817
    – cgnieder
    Jun 12, 2016 at 16:05
  • 1
    I believe you can just use \pagename for each language. For example it translates to Pagina for Dutch on my system.
    – cgnieder
    Jun 12, 2016 at 16:12
  • @clemens Ok understood. Indeed, in this use case there is no need to ask for the translation as the system is transparent. What if I needed to use polyglossia, will \pagename be translated as well? On my side, babel was complaining he couldn't find a dutch.ldf file. As I have a minimal installation, I had to perform a tlmgr install babel-dutch. I got "pagina" too.
    – wget
    Jun 12, 2016 at 16:29

1 Answer 1

2

The first issue here is that you were using babel with the [base] option. That option loads only the minimum for babel. Even babel internal commands like \bbl@loaded are not reachable and you will have no way to check which language has been loaded. The best bet here is to load a fallback language like English when no language is specified to your class file.

The second issue is that commands are NOT prefixed by the language name. So using \pagenameshould work. The content is automatically adapted according the currently loaded language.

And the last one, like specified, you need to make sure the translation you want to load is actually installed alongside babel. Babel does not come with all languages it support by default. Each language has its dedicated package name: babel-frenchfor french, babel-dutch for Dutch, etc. If you have no complete LaTeX distribution installed and have somewhat a "minimal" install, you can make sure the language addon is installed using the tlmgr command (if using TeXlive).

The code corrected:

\documentclass{report}

\usepackage[french]{babel}
\usepackage{translations}

\DeclareTranslationFallback{pageOfPages}
{\pagename~\thepage~of~\pageref{lastPage}}
\DeclareTranslation{English}{pageOfPages}
{\pagename~\thepage~of~\pageref{lastPage}}
\DeclareTranslation{Dutch}{pageOfPages}
{\pagename~\thepage~op~\pageref{lastPage}}
\DeclareTranslation{French}{page-of-pages}
{\pagename~\thepage~de~\pageref{lastPage}}

\begin{document}

\GetTranslation{pageOfPages}

\label{lastPage}
\end{document}

Btw, there is really a \frenchpagename command, but I still don't know from where it comes from as it is not defined in frenchb.dtx.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .