When I type in the Marathi language, LibreOffice incorrectly identifies it as Hindi, because both languages use the Devanagari script. This can affect language-specific features such as spellchecking and hyphenation.
I suggest integrating a language identification model such as FastText. The model lid.176.ftz is lightweight (less than 1 MB), highly accurate and fast.
I am not sure about legal / copyright issues.