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.
blauin my TeXlive directory the only relevant I can find is https://i.stack.imgur.com/mrXlS.png . So I'd say not particularly usable here. – user202729 Nov 19 '22 at 19:54\color{blue}rather than\bluebut that was an arbitrary choice. You could translate all command names such as\begin(context had that posibility) but why just colors? – David Carlisle Nov 19 '22 at 20:01blueeach time I use this color but rather a semantic macro for it (e.g.,\actionColor), I don't wish to write blau each time either. Rather,\actionColorshould be automatically displayed in German on need (say, via\GetTranslation{\actionColor}). – Nov 19 '22 at 20:21translationsdoesn't like macros as arguments. Runningpdflatexon https://pastebin.com/raw/AdqmEaPp producesDie Aktionen werden “actionColor gesetzt.in the output PDF file. That's NOT what we want :-(. – Nov 19 '22 at 20:41\expandafterit seems:Die Aktionen werden \ifdefempty{\actionColor}{in Textfarbe}{\expandafter\GetTranslation\expandafter{\actionColor}} gesetzt.– Qrrbrbirlbel Nov 19 '22 at 20:46translatorpackage would allow for writing\newtranslation[to=German]{blue}{blau}in the preamble and simply\translate{\actionColor}in the document text, without any\expandafter. So why have you suggestedtranslationsand nottranslator? – Nov 19 '22 at 21:35\expandafterisn't the worst thing (since you can always let a macro do this).maybe thetranslationpackage 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.) – Qrrbrbirlbel Nov 20 '22 at 02:11