# Polyglossia language from script?

When the different languages I use in a document have different scripts, can I implicitly set language from the script?

Here is a MWE in English and Russian where the Russian works fine when marked up as it should. My wish is to be able to say that cyrillic script means Russian so that the last paragraph also is done right.

% -*- TeX-engine: xetex; -*-
\documentclass[draft]{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{russian}
\setmainfont{Linux Libertine}

\begin{document}
\hsize 4.6cm

This is the main text is English.

\begin{russian}
Русский язык очень красивый.
\end{russian}

Русский язык очень красивый.
\end{document}


• Yes, of course, that's why my question starts with the sentence it starts with. – pst Dec 17 '15 at 5:17
• Yes, why do you think I don't know or think about that, again? – pst Dec 17 '15 at 15:00
• i didn't interpret your first sentence to mean that no script could appear for more than one language. that was a mistaken interpretation, it seems. i have removed my earlier comments. – barbara beeton Dec 17 '15 at 17:27

You can use ucharclasses, but my recommendation is to mark up your document with language changes.

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{russian}
\setmainfont{Linux Libertine O}

\usepackage[Latin,Cyrillics]{ucharclasses}

\setTransitionsForCyrillics
{\begingroup\hyphenrules{russian}}
{\endgroup}

\begin{document}
\hsize 4.7cm

This is the supercalifragilisticexpialidocious text

Русский язык очень красивый.

This is the supercalifragilisticexpialidocious text

\end{document}


• Great! (In the actual document I need something slightly more complicated, with a little test, since I only want a default when the language isn't set to one suitable for the new script.) – pst Dec 17 '15 at 5:51