5

From section titles and bookmarks point of view, translated strings from translator package behave differently, depending if they are defined directly within the .tex file or in a dictionary: in the latter case, both section title and bookmark just display the key of the translated string instead of the translation.

Case okay both in section title and in bookmark

In the following MCE, a translated string directly defined within the .tex file is used in a section title via the \translatelet macro:

\documentclass[english]{article}
\usepackage{translator}
\usepackage{babel}
\usepackage{hyperref}
%
\deftranslation[to=English]{key-from-document}{translation from document}
%
\translatelet\MacroFromDocument{key-from-document}
%
\begin{document}
\section{\MacroFromDocument}
Indirect (macro) use of \verb|\translate| (from document).
\end{document}

This case is

  • okay in section title,
  • okay in bookmark,

as the translation "translation from document" appears in both of them

Case okay in section title but not okay in bookmark

In the following MCE, a translated string directly defined within the .tex file is used in a section title directly with \translate:

\documentclass[english]{article}
\usepackage{translator}
\usepackage{babel}
\usepackage{hyperref}
%
\deftranslation[to=English]{key-from-document}{translation from document}
%
\begin{document}
\section{\translate{key-from-document}}
Direct use of \verb|\translate| (from document).
\end{document}

This case is:

  • okay in section title: the translation "translation from document" appears in it,
  • not okay in bookmark: the translation is replaced by the key "key-from-document".

Case not okay both in section title and in bookmark

In the following MCE, a translated string defined in a dictionary is used in a section title via the \translatelet macro and directly with \translate:

\begin{filecontents}{mydictionary.dict}
\ProvidesDictionary{mydictionary}{English}
\deftranslation{key-from-dictionary}{translation from dictionary}
\end{filecontents}
%
\documentclass[english]{article}
\usepackage{translator}
\usepackage{babel}
\usepackage{hyperref}
%
\deftranslation[to=English]{key-from-document}{translation from document}
\translatelet\MacroFromDictionary{key-from-dictionary}
%
\begin{document}
\section{\MacroFromDictionary}
Indirect (macro) use of \verb|\translate| (from dictionary).
\section{\translate{key-from-dictionary}}
Direct use of \verb|\translate| (from dictionary).
\end{document}

This case is:

  • not okay in section titles: the translation is replaced by the key "key-from-document",
  • not okay in bookmarks: the translation is replaced by the key "key-from-document".

All the wrong cases are related to the hyperref warning: "Token not allowed in a PDF string (PDFDocEncoding): [...] removing `\translate ' on input line [...]" but I can't figure out how to solve it.

4

The following appears to work. I have

  1. renamed the dictionary to mydictionary-English
  2. added \usedictionary {mydictionary} to the preamble

Code for your last case:

edit: apologies I just checked for the section headings, not the bookmarks; the bookmarks are yet another problem. The indirect use is ok, but the direct use of the (protected) \translate macro is not to hyperref's liking.

\documentclass[english]{article}
\usepackage{translator}
\usepackage{babel}
\usepackage{hyperref}
\usepackage{filecontents}

\begin{filecontents*}{mydictionary-English.dict}
\ProvidesDictionary{mydictionary}{English}
\deftranslation{key-from-dictionary}{translation from dictionary}
\end{filecontents*}
\usedictionary {mydictionary}


\begin{document}

\translatelet\MacroFromDictionary{key-from-dictionary}

\section{\MacroFromDictionary}
Indirect (macro) use of \verb|\translate| (from dictionary).

\section{\translate{key-from-dictionary}}
Direct use of \verb|\translate| (from dictionary).
\end{document}
  • Anyway, your answer helped me a lot as it pointed out that, with a dictionary (sorry for the misuse of it), the indirect use is okay as long as the \translatelet macro is defined within the document body (and not in preamble). – Denis Bitouzé Jun 19 '13 at 15:17
  • 1
    I just come back from reading the doc of translator and it says the package loads the dictionaries at begin document. This might explain why \translatelet should be used in the body. Apart from that, as the \translate command is unexpandable, I see no easy way apart precisely what you call the indirect way with \translatelet to get your bookmarks right. – user4686 Jun 19 '13 at 15:20
  • 1
    The fact that \translate is unexpandable is the main reason why I wrote the translations package (as part of the exsheets bundle)... – clemens Jul 6 '13 at 12:40

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.