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"
5
  • Polyglossia allows for typesetting in different languages but doesn't do the translating for you. Just wanted to make that clear. Commented Apr 19, 2021 at 13:23
  • @AML And do you know what package can I use for that purpose? Commented Apr 19, 2021 at 13:26
  • 2
    There is multilang, mentioned in one of the answers to tex.stackexchange.com/questions/60781/…. Commented Apr 19, 2021 at 13:40
  • you could do this but it is probably easier to simply have three files, one for each language Commented Apr 19, 2021 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. Commented Apr 20, 2021 at 8:42

1 Answer 1

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.

4
  • 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. Commented Apr 23, 2021 at 9: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. Commented Apr 23, 2021 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! Commented Apr 23, 2021 at 17:22
  • I tested it and it works perfectly. Thanks again! PS There is a small typo in your answer: \usepacakgeshould be \usepackage. Commented Apr 23, 2021 at 18:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.