# Detect main/default language from polyglossia

I'm creating a mystyle.sty package that sets backgrounds, styles and an introduction. The main .tex file only contains few package loading and options, and of course the main text. One of the options is

\setdefaultlanguage{finnish}


What I need is that the introduction part (in the package) would change to e.g. english should I change the default language to english too. So the question is:

1. If possible, how do I detect the language that is set by the command \setdefaultlanguage?
2. Which would be the simplest way to use this information to choose the appropriate intro?

For the second question, the introtext commands are stored to, say, \introinfinnish and \introinenglish. Number of different languages are not restricted to two.

A minimal XeLaTeX example (main.tex):

\documentclass[12pt,a4paper]{memoir}

\usepackage{fontspec}

\usepackage{polyglossia}
\setdefaultlanguage{finnish} % (english)
\setotherlanguage{english}

\usepackage{mystyle}

\begin{document}
\intropage % from mystyle
\clearpage

Something in finnish % (english)
\end{document}


and the package (mystyle.sty)

\ProvidesPackage{mystyle}
\newcommand{\introinfinnish}{Text in finnish...}
\newcommand{\introinenglish}{Text in english...}

% some commands that selects the correct introtext and stores it into \introtext

\newcommand{\intropage}{ % just a sketch
\@date
\vfill
\introtext
}

-

The main language is stored in \xpg@main@language, so something like the following will do.

\ProvidesPackage{mystyle}
\newcommand{\introinfinnish}{Text in finnish...}
\newcommand{\introinenglish}{Text in english...}

% some commands that selects the correct introtext and stores it into \introtext

\newcommand{\intropage}{% just a sketch
\@date
\vfill
\@ifundefined{introin\xpg@main@language}
{\PackageWarningNoLine{mystyle}{No introduction for \xpg@main@language'}%
\introinenglish}
{\@nameuse{introin\xpg@main@language}}
}


As you see, you can use any language you wish, provided you give a definition fo \introin<language>.

Please, use \setmainlanguage rather than the deprecated \setdefaultlanguage

-
Very nice and simple solution! Including new intro texts with other languages couldn't be anymore simple. And thanks for the hint on using \setmainlanguage`. –  TKO Jun 18 '13 at 8:35