1

Why does the following code not produce two lines of text with the single word "baz" each? (Instead there is only one line for the direct call to GetTranslation).

\documentclass{article}

\RequirePackage{translations}

\DeclareTranslationFallback {foo-bar}{baz}
\DeclareTranslation{English}{foo-bar}{baz}

\newcommand{\asdf}[1]{
  \edef\translationkey{foo-#1}%
  \GetTranslation{\translationkey}
}

\begin{document}

\GetTranslation{foo-bar}

\asdf{bar}

\end{document}

I suppose it has something to do with when macros are evaluated.

  • 1
    \expandafter\GetTranslation\expandafter{\translationkey} -- you must expand the \translationkey first before feeding it to \GetTranslation –  Aug 23 '16 at 17:11
  • 1
    I guess your MWE is a simplification of the real use case? Otherwise you get the same thing easier: \newcommand{\asdf}[1]{\GetTranslation{foo-#1}} – cgnieder Aug 23 '16 at 17:30

1 Answers1

2

Indeed, the argument \translationkey must be expanded in order to be digested by \GetTranslation.

\documentclass{article}

\RequirePackage{translations}

\DeclareTranslationFallback {foo-bar}{baz}
\DeclareTranslation{English}{foo-bar}{baz}

\newcommand{\asdf}[1]{%
  \edef\translationkey{foo-#1}%
  \expandafter\GetTranslation\expandafter{\translationkey}%
}

\begin{document}

\GetTranslation{foo-bar}

\asdf{bar}

\end{document}

enter image description here