-
Notifications
You must be signed in to change notification settings - Fork 4
Home
The translations
package is an alternative to the translator
package (part of the beamer
bundle) that was needed since it turned out that the \translate
macro wasn't expandable. However, there are more differences to translator
and there may also be reasons why one might want to use translations
instead of babel
's \addto\captions<lang>
mechanism or KOMA-Script's \providecaptionname
.
If there are language aliases you have to provide a translation for every variant:
\documentclass{article}
\usepackage[ngerman]{babel}
\def\colorname{color}
\addto\captionsgerman{\def\colorname{Farbe}}
\addto\captionsngerman{\def\colorname{Farbe}}
\addto\captionsgermanb{\def\colorname{Farbe}}
\addto\captionsaustrian{\def\colorname{Farbe}}
\addto\captionsnaustrian{\def\colorname{Farbe}}
\begin{document}
\colorname\ = Farbe
\end{document}
This has the same “drawback” as the babel
way: you need to provide a translation for every variant:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{scrbase}
\def\colorname{color}
\providecaptionname{german}\colorname{Farbe}
\providecaptionname{germanb}\colorname{Farbe}
\providecaptionname{ngerman}\colorname{Farbe}
\providecaptionname{austrian}\colorname{Farbe}
\providecaptionname{naustrian}\colorname{Farbe}
\begin{document}
\colorname\ = Farbe
\end{document}
This is easier with translator
:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[ngerman]{translator}
\newtranslation[to=German]{color}{Farbe}
\def\colorname{\translate{color}}
\begin{document}
\colorname\ = Farbe
\end{document}
However, the package needs to be told the document language explicitly and \translate
is not expandable.
Quite similar to translator
but \GetTranslations
is expandable and the package recognizes the document language automatically:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{translations}
\DeclareTranslation{German}{color}{Farbe}
\def\colorname{\GetTranslation{color}}
\begin{document}
\colorname\ = Farbe
\end{document}
translations
also knows the concept of dialects which means it is easy to provide different translations for different dialects.
\documentclass{article}
\usepackage[british]{babel}
\usepackage{translations}
\DeclareTranslation{English}{color}{color}
\DeclareTranslation{British}{color}{colour}
\def\colorname{\GetTranslation{color}}
\begin{document}
\colorname\ = colour
\end{document}
If there wasn't a translation for the dialect but only for it's base language translations
would use that instead. The same does not work with translator
:
\documentclass[british]{article}
\usepackage{babel}
\usepackage{translator}
\newtranslation[to=English]{color}{color}
\newtranslation[to=British]{color}{colour}
\def\colorname{\translate{color}}
\begin{document}
\colorname\ = color
\end{document}