Let's say we wish to verbalize the colors used in a document in the current language:
\documentclass[USenglish,ngerman]{article}
\pagestyle{empty}
\usepackage{babel}
\usepackage[x11names]{xcolor}
\usepackage{etoolbox}
\newcommand{\actionColor}{blue}
\newcommand{\actionColorGerman}{blau}
\begin{document}
Die Aktionen werden \ifdefempty{\actionColorGerman}{in Textfarbe}{\actionColorGerman} gesetzt.
\end{document}
yields
Die Aktionen werden blau gesetzt.
(Which means that the actions (whatever an action might mean in my text) are typeset blue.)
The current code is bad because \actionColor
and \actionColorGerman
are not tied together by a command. For example, if you change/remove one (say, blue
), you may forget to change/remove the other (here, blau
). Moreover, if you have a dozen of different semantic color macros \doodahXYZColor
evaluating to blue
and another dozen \gimmickXYZColor
evaluating to red
, you'd have to add a dozen of translations \doodahXYZColorGerman
evaluating to blau
and another dozen of translations \gimmickXYZColorGerman
evaluating to rot
. This is useless duplication.
Has some package already done the exercise of automatically translating the color names? I don't wish to reinvent the bicycle. Ideally, I'd like to have a macro
\colorInCurrentLanguage{…}
that takes an argument (in our MWE, \actionColor
) and returns its translation in the current document language (in our MWE, blau
).
For my current purposes, translations into German would do.
\expandafter
it seems:Die Aktionen werden \ifdefempty{\actionColor}{in Textfarbe}{\expandafter\GetTranslation\expandafter{\actionColor}} gesetzt.
\expandafter
isn't the worst thing (since you can always let a macro do this).maybe thetranslation
package provides more tools and macros to solve this. (Though, I'm surprised it breaks. I've expected it to expand its argument in the first place.)