ConTeXt provides a proof of concept module for such translations: m-translate. You could use it to translate text, but the translation takes place before macro expansion. So, the method will fail if the translation string is part of a macro name.
The translation can be enabled and disabled using \enableinputtranstion
and \disableinputtranslation
. Here is an example, which a little wrapper macro for ease of input.
\usemodule[translate]\define\defineautocoloring {\dodoubleargument\dodefineautocoloring}\def\dodefineautocoloring[#1][#2]% {\def\dododefineautocoloring##1% {\translateinput[##1][{\color[#1]{##1}}]}% \processcommalist[#2]\dododefineautocoloring}\defineautocoloring[red][foo, bar]\defineautocoloring[blue][color]\setuppapersize[A5]\starttext\enableinputtranslationThis is a foo example of coloring random bar text. What is foobar? Thetranslation is done before macro expansion, so weird stuff can happen:\type{foobar}\disableinputtranslationThis is a foo example of coloring random bar text. What is foobar? Thetranslation is done before macro expansion, so weird stuff can happen:\type{foobar}\stoptext
which gives