I have a collection of documents that share a common style file that has all the functions and templating shared by this particular collection. The majority of these are all in the same language, but o handful of them are actually translations of the others. I would like to keep using the same style include file, but a few tidbits (for example in the footer and title sheet) need to be adjusted per-language.

I'm using polyglossia1, and each document has its own language declaration using \setmainlanguage{} (in my case, mostly to Turkish). Is there some way to retrieve what language has been set and conditional output different strings based on which language is the document default?

1 Actually for some reason my style file also has \usepackage[turkish]{babel}, which seems to be should be redundant and potentially a conflict with polyglossia; maybe I should sort out why that got in there while I'm messing with this!

  • Both babel and polyglossia have \languagename which holds the currently active language name. And the translations package offers \ifcurrentbaselanguage{<lang>}{<true>}{<false>} for tests – clemens Mar 15 '15 at 11:04

polyglossia stores the main language name in the macro \xpg@main@language, so it's easy to achieve what you want.








This document is written in \mainlanguage.

\IfStrEq{\mainlanguage}{turkish}{Yes, it's Turkish!}{No, it's not Turkish!}



enter image description here

As a side note, don't use babel if you're using polyglossia already...

  • 1
    In modern times, you can safely use babel with the new engines. But using babel and polyglossia is bad indeed. – Johannes_B Mar 15 '15 at 10:34
  • Both babel and polyglossia have \languagename which holds the currently active language name. No need for \xpg@main@language – clemens Mar 15 '15 at 11:05
  • @clemens as you say, \languagename holds the "currently active" language, not the "main" language as requested by the OP... – karlkoeller Mar 15 '15 at 11:13
  • But the OP says every of his documents has only one language so I don't see the difference here (although, I'm not sure \languagename can be trusted before begin document...) – clemens Mar 15 '15 at 11:28
  • 1
    @clemens Actually it's pretty useful to know both options because my documents are not exclusively one language are the other, both directions have bits from other languages. – Caleb Mar 15 '15 at 14:53

protected by Community Mar 18 '15 at 3:46

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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