11

I've got a template that is to be used in french or english, is there a name in babel defining the "of" of "page x of yy" than I want to translate automaticaly to "page x sur y"

If not, is there a way of setting a name according to language selected in babel.

11

Two packages come to mind: translator (from the beamer bundle) and translations. I'll show an example for both each giving the following output:

First page: enter image description here Second page: enter image description here


Here's the translations version:

\documentclass{article}
\usepackage[ngerman,french,english]{babel}
\usepackage[lastpage,user]{zref}

\usepackage{translations}
% used when a language is used for which no translation exists:
\DeclareTranslationFallback{page-of-pages}
  {page~\thepage\ of~\zpageref{LastPage}}

% translations:
\DeclareTranslation{German}{page-of-pages}
  {Seite~\thepage\ von~\zpageref{LastPage}}
\DeclareTranslation{French}{page-of-pages}
  {page~\thepage\ sur~\zpageref{LastPage}}
\DeclareTranslation{English}{page-of-pages}
  {page~\thepage\ of~\zpageref{LastPage}}


\begin{document}
\selectlanguage{ngerman}
\GetTranslation{page-of-pages}

\selectlanguage{french}
\GetTranslation{page-of-pages}

\selectlanguage{english}
\GetTranslation{page-of-pages}

\newpage
\selectlanguage{ngerman}
\GetTranslation{page-of-pages}

\selectlanguage{french}
\GetTranslation{page-of-pages}

\selectlanguage{english}
\GetTranslation{page-of-pages}

\end{document}

Here's the analogous version with translator. Note, that it needs to know the languages by providing them as option which is done here by declaring them as class option:

\documentclass[ngerman,french,english]{article}
\usepackage{babel}
\usepackage[lastpage,user]{zref}

\usepackage{translator}
\newtranslation[to=German]{page-of-pages}
  {Seite~\thepage\ von~\zpageref{LastPage}}
\newtranslation[to=French]{page-of-pages}
  {page~\thepage\ sur~\zpageref{LastPage}}
\newtranslation[to=English]{page-of-pages}
  {page~\thepage\ of~\zpageref{LastPage}}


\begin{document}
\selectlanguage{ngerman}
\translate{page-of-pages}

\selectlanguage{french}
\translate{page-of-pages}

\selectlanguage{english}
\translate{page-of-pages}

\newpage
\selectlanguage{ngerman}
\translate{page-of-pages}

\selectlanguage{french}
\translate{page-of-pages}

\selectlanguage{english}
\translate{page-of-pages}

\end{document}
3

For a limited scope, one can do it manually:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,french]{babel}
\usepackage{lastpage}

\makeatletter
\newcommand{\pageofpages}{%
  \@ifundefined{pageof@\languagename}
    {page \thepage\ of \pageref{LastPage}} % a default
    {\@nameuse{pageof@\languagename}}%
 }
% English is already default
% \newcommand{\pageof@english}{page \thepage\ of \pageref{LastPage}}
% French
\newcommand{\pageof@french}{page \thepage\ sur \pageref{LastPage}}
\makeatother

\begin{document}

\pageofpages\newpage

\selectlanguage{english}
\pageofpages\newpage

\pageofpages

\selectlanguage{french}\pageofpages

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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