At the time of writing this answer, XeLaTeX is very far from LuaLaTeX in multilingual typesetting. I provide the following example which can be run with both XeLaTeX and LuaLaTeX. The objective is to typeset a multilingual document involving four languages. 1) English (main) 2) Malayalam 3) Marathi 4) Hindi. We use fonts already distributed with TeX Live. Tested with fully updated TeX Live 2024 (full installation). Marathi and Hindi share the same scripts, but differ in some typographic conventions. Especially with respect to two characters `ल` and `श`.
```
\documentclass{article}
\usepackage{babel}
\usepackage{hologo}
\usepackage{iftex}
\babelprovide[import,main]{english}
\ifLuaTeX
\babelprovide[%
import,%
onchar = {ids fonts}%
]{malayalam}
\babelprovide[%
import,%
onchar = {ids fonts}%
]{marathi}
\babelprovide[%
import,%
onchar = {ids fonts}%
]{hindi}
\else
\babelprovide[import]{malayalam}
\babelprovide[import]{marathi}
\babelprovide[import]{hindi}
\fi
\usepackage{fontspec}
\babelfont{rm}[%
BoldFont = {NewCM10-Bold.otf},%
ItalicFont = {NewCM10-BookItalic.otf}%
]{NewCM10-Book.otf}
\babelfont{sf}[%
BoldFont = {NewCMSans10-Bold.otf},%
ItalicFont = {NewCMSans10-BookOblique.otf}%
]{NewCMSans10-Book.otf}
\babelfont{tt}[%
BoldFont = {NewCMMono10-Bold.otf},%
ItalicFont = {NewCMMono10-BookItalic.otf}%
]{NewCMMono10-Book.otf}
\babelfont[malayalam]{rm}[%
Scale = {1.275},%
% Scale the font to treat both the scripts equally. This
% is a new typographic trend to democratise typesetting!
Script = {Malayalam},%
Renderer = {HarfBuzz},%
BoldFont = {RIT-Rachana-Bold.ttf},%
ItalicFont = {Rit-Rachana-Regular.ttf}%
]{Rit-Rachana-Regular.ttf}
\babelfont[malayalam]{sf}[%
Scale = {1.275},%
Script = {Malayalam},%
Renderer = {HarfBuzz}%
]{RIT-MeeraNew.ttf}
\babelfont[malayalam]{tt}[%
Scale = {1.275},%
Script = {Malayalam},%
Renderer = {HarfBuzz}%
]{RIT-tnjoy-regular.ttf}
\babelfont[marathi]{rm}[%
Script = {Devanagari},%
Language = {Marathi},%
Renderer = {HarfBuzz},%
BoldFont = {Eczar-Bold.otf},%
ItalicFont = {Eczar-Regular.otf}%
]{Eczar-Regular.otf}
\babelfont[marathi]{sf}[%
Script = {Devanagari},%
Language = {Marathi},%
Renderer = {HarfBuzz}
]{Mukta-Regular.ttf}
\babelfont[marathi]{tt}[%
Script = {Devanagari},%
Language = {Marathi},%
Renderer = {HarfBuzz}%
]{Baloo2-Regular.ttf}
\babelfont[hindi]{rm}[%
Script = {Devanagari},%
Language = {Hindi},%
Renderer = {HarfBuzz},%
BoldFont = {Eczar-Bold.otf},%
ItalicFont = {Eczar-Regular.otf}%
]{Eczar-Regular.otf}
\babelfont[hindi]{sf}[%
Script = {Devanagari},%
Language = {Hindi},%
Renderer = {HarfBuzz}%
]{Mukta-Regular.ttf}
\babelfont[hindi]{tt}[%
Script = {Devanagari},%
Language = {Hindi},%
Renderer = {HarfBuzz}%
]{Baloo2-Regular.ttf}
\begin{document}
\setlength{\parindent}{0pt}
\section*{With markup}
\emph{Comments:}
Works correctly with both \hologo{LuaLaTeX} and
\hologo{XeLaTeX}.
\subsection*{Serif}
\begingroup
hello world
NewCM10-Book.otf
\selectlanguage{malayalam}
മലയാളം
\foreignlanguage{english}{RIT-Rachana-Regular.ttf}
\selectlanguage{marathi}
शालेय शिक्षणाचे महत्त्व.
\foreignlanguage{english}{Marathi text in Eczar-Regular.otf
with Marathi} ल श
\selectlanguage{hindi}
शालेय शिक्षा का महत्त्व।
\foreignlanguage{english}{Hindi text in Eczar-Regular.otf
with Hindi} ल श
\endgroup
\subsection*{Sans serif}
\begingroup
\sffamily
hello world
NewCMSans10-Book.otf
\selectlanguage{malayalam}
മലയാളം
\foreignlanguage{english}{RIT-MeeraNew.ttf}
\selectlanguage{marathi}
शालेय शिक्षणाचे महत्त्व.
\foreignlanguage{english}{Marathi text in Mukta-Regular.ttf
with Marathi} ल श
\selectlanguage{hindi}
शालेय शिक्षा का महत्त्व।
\foreignlanguage{english}{Hindi text in Mukta-Regular.ttf
with Hindi} ल श
\endgroup
\subsection*{Monospaced}
\begingroup
\ttfamily
hello world
NewCMMono10-Book.otf
\selectlanguage{malayalam}
മലയാളം
\foreignlanguage{english}{RIT-tnjoy-regular.ttf}
\selectlanguage{marathi}
शालेय शिक्षणाचे महत्त्व.
\foreignlanguage{english}{Marathi text in Baloo2-Regular.ttf
with Marathi} ल श
\selectlanguage{hindi}
शालेय शिक्षा का महत्त्व।
\foreignlanguage{english}{Hindi text in Baloo2-Regular.ttf
with Hindi} ल श
\endgroup
\newpage
\section*{Without markup}
\emph{Comments:}
Works correctly with \hologo{LuaLaTeX}, but fails to detect
two languages that use the same script. Can partially work
with \hologo{XeLaTeX} using package \textsf{ucharclasses},
but a) it is not a reliable solution as documented in the
package documentation itself; b) it doesn't support font
switching between families.
\subsection*{Serif}
\begingroup
hello world
NewCM10-Book.otf
മലയാളം
RIT-Rachana-Regular.ttf
शालेय शिक्षणाचे महत्त्व.
Marathi text in Eczar-Regular.otf, but Hindi ल श
शालेय शिक्षा का महत्त्व।
Hindi text in Eczar-Regular.otf with Hindi ल श
\endgroup
\subsection*{Sans serif}
\begingroup
\sffamily
hello world
NewCMSans10-Book.otf
മലയാളം
RIT-MeeraNew.ttf
शालेय शिक्षणाचे महत्त्व.
Marathi text in Mukta-Regular.ttf, but Hindi ल श
शालेय शिक्षा का महत्त्व।
Hindi text in Mukta-Regular.ttf with Hindi ल श
\endgroup
\subsection*{Monospaced}
\begingroup
\ttfamily
hello world
NewCMMono10-Book.otf
മലയാളം
RIT-tnjoy-regular.ttf
शालेय शिक्षणाचे महत्त्व.
Marathi text in Baloo2-Regular.ttf, but Hindi ल श
शालेय शिक्षा का महत्त्व।
Hindi text in Baloo2-Regular.ttf with Hindi ल श
\endgroup
\end{document}
```
Conclusions:
--
1. LuaLaTeX is able to detect languages based on the Unicode characters used and doesn't require markup. XeLaTeX isn't able to do this and requires explicit markup for language switching.
2. LuaLaTeX cannot detect languages which share one script. But IMHO it's an extremely difficult task with which even top-notch AI would struggle. As an example consider the words शालेय, महत्त्व, शिक्षा and का seen in the examples. All these four words are present in both Hindi and Marathi*. Without analysing the sentence, it would be impossible to detect the language which as of now no programme (not even the recent AIs) can do.
\* Fun facts: 1) The first three of the four words listed here are borrowed to Marathi and Hindi from an ancient language Sanskrit. There is a slight chance that another language Nepali (which uses Devanagari script and also heavily borrows from Sanskrit) too has them, but I can't be sure as I don't speak Nepali. 2) Third and fourth words mean completely different things in both Hindi and Marathi. शिक्षा means education in Hindi and punishment in Marathi (well, not too different if observed carefully :P). 3) Funnily, it can mean both in Sanskrit. Have no idea what happens in Nepali. 4) Fourth word is the funniest. It is _which (feminine)_ of Sanskrit, _a yes/no auxiliary_ of Marathi and the masculine genitive case of Hindi. Again, have to check a) if it exists in Nepali or not b) if it does, does it make the picture more bizarre or not.