Let's say we wish to verbalize the colors used in a document in the current language:

Die Aktionen werden \ifdefempty{\actionColorGerman}{in Textfarbe}{\actionColorGerman} gesetzt.


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


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.

  • I guess taking a list of color names and copy pasting it into Google translate would be an option? This seems oddly specific.
    – user202729
    Commented Nov 19, 2022 at 19:30
  • 1
    q176058 seems like one way to solve this. Commented Nov 19, 2022 at 19:45
  • @user202729 No, as some kind of switch statement taking an English color and returning a foreign-language color (and a default string if no translation has been found) would still be needed. Also, translations may vary. And, most important, I don't wish to bloat up the code with strings potentially already stored somewhere deep in babel, xcolor, or related packages.
    – user282514
    Commented Nov 19, 2022 at 19:46
  • 1
    @AlbertNash You're going to need \expandafter it seems: Die Aktionen werden \ifdefempty{\actionColor}{in Textfarbe}{\expandafter\GetTranslation\expandafter{\actionColor}} gesetzt. Commented Nov 19, 2022 at 20:46
  • 1
    @AlbertNash Both packages are mentioned in the linked question. I don't have any experience with any of them. I certainly don't know the advantages or drawbacks of either package. Having to use \expandafter isn't the worst thing (since you can always let a macro do this).maybe the translation 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.) Commented Nov 20, 2022 at 2:11


You must log in to answer this question.