2

This is probably a rather simple question, but I couldn't find it answered: When I write e.g.

\pageref{Example}

the output is on page 12 for babel language English, but auf Seite 12 for babel language German.

I want to create custom language sets like this:

\createTranslation{insertTableTitle}
{english=Something, german=Etwas, italiano=Alcuno, default=Something}

When I call \insertTableTitle it expands to different strings, depending on the language. This example is pseudocode of course, but I'm pretty sure, there is some built-in command in babel that does the job.

What is the default way to do this or how is it handled at e.g. the title of the table of content?

Ingmar
  • 6,690
  • 5
  • 26
  • 47
MaestroGlanz
  • 2,348
  • The bog-standard builtin \pageref only prints the page number, not on page 12. You are loading some package with smart referencing; which is it? – Willie Wong Jul 27 '22 at 19:31

2 Answers2

3

The short answer is you write a conditional :-) How you implement the conditional there are options.

For example, the varioref package uses package options (avoiding babel altogether). Behold (copied from varioref.sty):

\DeclareOption{american}
  {\vref@addto\extrasamerican{%
    \def\reftextfaceafter {on the \reftextvario{facing}{next} page}%
    \def\reftextfacebefore{on the \reftextvario{facing}{preceding}
                           page}%
    \def\reftextafter     {on the \reftextvario{following}{next} page}%
    \def\reftextbefore    {on the \reftextvario{preceding}{previous} page}%
    \def\reftextcurrent   {on \reftextvario{this}{the current} page}%
    \def\reftextfaraway#1{on page~\pageref{#1}}%
    \def\reftextpagerange#1#2{on pages~\pageref{#1}--\pageref{#2}}%
    \def\reftextlabelrange#1#2{\ref{#1} to~\ref{#2}}%
    \let\vrefformat\vrefdefaultformat
    \let\Vrefformat\Vrefdefaultformat
    \let\fullrefformat\fullrefdefaultformat
    \let\vrefrangeformat\vrefrangedefaultformat
  }}
\DeclareOption{arabic}
  {\vref@addto\extrasarabic{%
    \def\reftextfaceafter {بالصفحة \reftextvario{المقابلة}{اللاحقة}}%
    \def\reftextfacebefore{بالصفحة \reftextvario{المقابلة}{المُنْصَرِمَةٌ}}%
    \def\reftextafter     {بالصفحة \reftextvario{اللاحقة}{التالية}}%
    \def\reftextbefore    {بالصفحة \reftextvario{السابقة}{المُنْصَرِمَةٌ}}%
    \def\reftextcurrent   {ب\reftextvario{الصفحة الحالية}{هذه الصفحة}}%
    \def\reftextfaraway#1{بالصفحة رقم~\pageref{#1}}%
    \def\reftextpagerange#1#2{بالصفحات~\pageref{#1}--\pageref{#2}}%
    \def\reftextlabelrange#1#2{\ref{#1} حتى~\ref{#2}}%
    \let\vrefformat\vrefdefaultformat
    \let\Vrefformat\Vrefdefaultformat
    \let\fullrefformat\fullrefdefaultformat
    \let\vrefrangeformat\vrefrangedefaultformat
  }}
\DeclareOption{austrian}
  {\vref@addto\extrasaustrian{%
    \def\reftextfaceafter {auf der n\"achsten Seite}%
    \def\reftextfacebefore{auf der vorherigen Seite}%
    \let\reftextafter     \reftextfaceafter
    \let\reftextbefore    \reftextfacebefore
    \def\reftextcurrent   {auf dieser Seite}%
    \def\reftextfaraway#1{auf Seite~\pageref{#1}}%
    \def\reftextpagerange#1#2{auf Seiten~\pageref{#1}--\pageref{#2}}%
    \def\reftextlabelrange#1#2{\ref{#1} bis~\ref{#2}}%
    \let\vrefrangeformat\vrefrangedefaultformat
  }}

If you want a babel-based solution, you can use the conditional

\iflanguage{<language>}{<true action>}{<false action>}

So something like

\newcommand\mytabletitle{%
   \iflanguage{english}{Something}{%
   \iflanguage{german}{Etwas}{%
   \iflanguage{italiano}{Alcuno}{%
      Something %default
   }}}}

and make your command print \mytabletitle instead of any hard-coded string of letters.

The answer to this question gives some other ways of using babel-based conditionals. Specifically, egreg provides a revamped version that uses a key-value syntax as you asked for in your original question. Rather than stealing his answer I'll just point you to it.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
3

You could use the translator package. That's what e.g. Beamer uses to translate strings like "Figure".

You'll find that it already comes with translations for many commonly used terms in its dictionaries, but you can also add new ones:

\documentclass[
ngerman
%english
]{article}

\usepackage{babel}

\usepackage{translator} \usedictionary{translator-basic-dictionary}

\newtranslation[to = German]{Something}{Etwas} \newtranslation[to = Italian]{Something}{Alcuno}

\begin{document}

\translate{table}

\translate{Something}

\end{document}