1

Question

How can I use polyglossia package to translate my document from one language to another?

The documentation and all examples online I have found show polyglossia package being used to product single document containing multiple languages, while I want to produce multiple documents each in a different language.

Example

For example having a document:

\setdefaultlanguage{english}
\setotherlanguage{polish}
\setotherlanguage{spanish}

\begin{document}

\textenglish{Hello} \textpolish{Cześć} \textspanish{Hola}

\end{document}

I'd like to produce 3 outputs:

  • output-en.pdf containing "Hello"
  • output-pl.pdf containing "Cześć"
  • output-es.pdf containing "Hola"
  • Polyglossia allows for typesetting in different languages but doesn't do the translating for you. Just wanted to make that clear. – AML Apr 19 '21 at 13:23
  • @AML And do you know what package can I use for that purpose? – Robert Kusznier Apr 19 '21 at 13:26
  • 2
    There is multilang, mentioned in one of the answers to https://tex.stackexchange.com/questions/60781/managing-multiple-translation-of-a-single-document. – Marijn Apr 19 '21 at 13:40
  • you could do this but it is probably easier to simply have three files, one for each language – David Carlisle Apr 19 '21 at 18:08
  • @DavidCarlisle I understand, but that would mean maintaining 3 separate copies of the same structure, differing only in texts. That's exactly what I'm trying to avoid. – Robert Kusznier Apr 20 '21 at 08:42

1 Answers1

2

I think you are looking for something like

spanish.tex

\documentclass[a4paper]{article}
\usepacakge{polyglossia}% actually I'd use babel
\setdefaultlanguage{spanish}
\def\textenglish#1{\ignorespaces}
\def\textpolish#1{\ignorespaces}
\input{main}

main.tex

\begin{document}

\textenglish{Hello} \textpolish{Cześć} \textspanish{Hola}

\end{document}

To get the Spanish-only document, and just make two more top level files to get the English and Polish versions.

David Carlisle
  • 757,742
  • Thanks! I think that should work. I'll test it today and if it works, I'll accept your answer. One more question: Why would you use babel over polyglossia? I am a novice in LaTeX and I chose Polyglossia only because I've read it aims to be a modern replacement for babel. – Robert Kusznier Apr 23 '21 at 09:36
  • @RobertKusznier babel is the standard latex language interface, polyglossia comes from a time when babel had no active developer and support for newer engines such as xelatex and luatex was lacking. But now babel is very actively developed and the situation is different. – David Carlisle Apr 23 '21 at 10:23
  • I actually thought the opposite! I read a little more now and I seem to be misinformed. Thanks for putting me on the right path! – Robert Kusznier Apr 23 '21 at 17:22
  • I tested it and it works perfectly. Thanks again! PS There is a small typo in your answer: \usepacakgeshould be \usepackage. – Robert Kusznier Apr 23 '21 at 18:47