5

I'm trying to create a localized document template including some boilerplate text blocks, using the translations package. Everything's working great so far, except I cannot declare translations spanning multiple paragraphs.

Whenever the translation string contains a paragraph break, compilation aborts with the following error:

ERROR: Paragraph ended before \NewTranslation was complete

I have tried wrapping the message inside an \mbox without success. Is there a way to have a translated message spanning multiple paragraphs?

I'm not really invested in the translations package, so if there's a better way to achieve my result, please let me know! :)

Here's a minimal working example illustrating the problem:

\documentclass{standalone}

\usepackage[ngerman]{babel}
\usepackage{translations}

\NewTranslation{ngerman}{template}{%
  Erster Absatz.

  Zweiter Absatz.
}

\begin{document}
\GetTranslation{template}
\end{document}
  • 3
    Welcome to TeX.se, and thanks for posting a MWE. Unfortunately all of the translations macros are defined as 'short' macros, i.e., ones that don't support \par inside them. I assume this is by design. You might want to contact the package author. – Alan Munn May 9 '17 at 15:54
  • Thanks for the quick reply, @AlanMunn! I had feared that this was the case - would you happen to know any good replacements to the translations package? – AdrianoKF May 9 '17 at 16:07
  • The translator package (part of beamer) can deal with paragraphs in translation definitions. I don't know much about either package however, to decide between them. – Alan Munn May 9 '17 at 16:20
  • @AlanMunn I'll implement this into translations. I didn't foresee that one might want long translations… – clemens May 9 '17 at 16:25
  • I just uploaded v1.6 (GitHub) to CTAN which allows paragraphs in translation replacements – clemens May 16 '17 at 9:22
2

All of the macros in the translations packages are defined as short macros which don't allow \par inside them. I assume this is by design. (Now that the package author has replied in the comments, it seems like this can be addressed as a feature request.)

The translator package, which is part of beamer does seem to allow paragraphs in translation definitions, however. Perhaps this can be useful for your task:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{translator}

\newtranslation[to=German]{template}{%
  Erster Absatz.

  Zweiter Absatz.
}

\begin{document}
\translate[to=German]{template}
\end{document}

output of code

As a temporary solution, you may be able to get away with using \endgraf instead of \par in your translations.

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{translations}

\NewTranslation{ngerman}{template}{%
  Erster Absatz.\endgraf
  Zweiter Absatz.
}

\begin{document}
\GetTranslation{template}
\end{document}

But this has its drawbacks, depending on context. See the following question for discussion.

  • 1
    Of course there's always \endgraf :) – clemens May 9 '17 at 16:27
  • @clemens I forgot about that. Is it really a viable (temporary) solution? – Alan Munn May 9 '17 at 16:29
  • @clemens The drawback with \endgraf is that it doesn't vary its behaviour like \par. (Try \begin{itemize} \item Foo\endgraf Bar. \item Foo\par Bar. \end{itemize}) It depends on the context the string will be used in. – Nicola Talbot May 9 '17 at 16:41
  • The \endgraf workaround suits my needs for now, since the template text will not appear inside complex environments. I will also consider the translator package for a more permanent solution! – AdrianoKF May 9 '17 at 16:52
  • @AdrianoKF Actually, given Clemens' response to you, you should probably not switch to the translator package, but simply wait for the new version of translations to be released. – Alan Munn May 9 '17 at 16:54
1

REVISION

This will accomplish it fully, requiring only that the template be expandable.

It takes (under the redefined name \NewTranslation) input including paragraphs, and parses through the \pars, converting them to \fauxpars. It calls on a saved version of the original \NewTranslation, using the input version containing the \fauxpar surrogates. Finally, one can call on \GetTranslation as in the original answer above.

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{translations}

\let\fauxpar\par
\let\svNewTranslation\NewTranslation
\renewcommand\NewTranslation[3]{%
  \def\tmp{}%
  \MyNewTranslationAux#3\par\relax%
  \expandafter\xdef\csname#2Aux\endcsname{\tmp}%
  \svNewTranslation{#1}{#2}{\csname#2Aux\endcsname}
}
\makeatletter
\long\def\MyNewTranslationAux#1\par#2\relax{%
  \g@addto@macro{\tmp}{#1}%
  \if\relax#2\else\g@addto@macro{\tmp}{\fauxpar}\MyNewTranslationAux#2\par\relax\fi%
}
\makeatother

\NewTranslation{ngerman}{templateA}{%
  Erster Absatz.
}
\NewTranslation{ngerman}{templateB}{%
  Erster Absatz.

  Zweiter Absatz.
}
\NewTranslation{ngerman}{templateC}{%
  Erster Absatz.

  Zweiter Absatz.

  Third Absatz.
}
\begin{document}
\GetTranslation{templateA}\medskip

\GetTranslation{templateB}\medskip

\edef\foo{\GetTranslation{templateC}}
\foo
\end{document}

enter image description here

ORIGINAL SIMPLER APPROACH

Depending on your need, this answer may be wholly unacceptable, or it may get you out of a pinch. If one uses a surrogate \fauxpar macro for your input replacement for \par, it will work.

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{translations}

\NewTranslation{ngerman}{template}{%
  Erster Absatz.
\fauxpar
  Zweiter Absatz.
}
\let\fauxpar\par
\begin{document}
\GetTranslation{template}
\end{document}

enter image description here

  • Unfortunately this looses the expandability of \GetTranslation – clemens May 10 '17 at 11:41
  • @clemens Can you elaborate, since I know nothing of what this package does? – Steven B. Segletes May 10 '17 at 11:50
  • 1
    \edef\foo{\GetTranslation{blah}} works, \edef\foo{\MyGetTranslation{blah}} doesn't… – clemens May 10 '17 at 11:58
  • @clemens I remedied the issue. – Steven B. Segletes May 10 '17 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.