How to Detect the Language of a Text (and Spot Mixed Languages)
How language detection works with scripts and common words, why short texts and close languages are hard, and how to find mixed-language sentences.
&c=%230f766e&k=text)
"What language is this?" sounds like a simple question until you have to answer it for a thousand support emails, survey comments or product reviews. Language identification is the first step for routing a message to the right team, picking a translation pair, setting the lang attribute of a web page for search engines and screen readers, or choosing the correct spell checker.
Stage one: the script
Every letter belongs to a writing system, which Unicode calls a script. Some scripts are used by one language only. Thai letters mean Thai, Georgian letters mean Georgian, Hangul means Korean. When the text contains hiragana or katakana, it is Japanese, even though Japanese also uses Chinese characters.
Other scripts are shared. Latin letters are used by hundreds of languages, Cyrillic by Russian, Ukrainian, Bulgarian, Serbian, Kazakh and more, Arabic script by Arabic, Persian, Urdu and Pashto, and Devanagari by Hindi, Marathi and Nepali. For these, a second stage is needed.
Stage two: words and letters
Every language has short words that appear in almost every sentence: the, and, of in English; el, la, que in Spanish; der, die, und in German. Counting how many of the words in a text belong to each language's common-word list gives a strong signal. Special letters add more evidence: ñ points to Spanish, ß to German, ő to Hungarian, і and ї to Ukrainian, پ and گ to Persian, ٹ and ے to Urdu.
The built-in engine of the Language Detector combines both stages for about 80 languages and answers instantly. For a wider range, you can switch to franc, an open-source detector that compares three-letter sequences against profiles of 187 languages. It loads once (about 360 KB) and also runs inside your browser.
Reading the result
The tool shows the main language, its code, the script, and a confidence score. Below that, the runner-up languages show how close the decision was. If English is at 80 % and the next language at 5 %, the answer is clear. If Danish and Norwegian are both near 40 %, the text is too short or too neutral to tell them apart.
The scripts panel shows the share of each writing system, which helps with transliterated or mixed text.
Mixed-language text
Real messages are often mixed. A customer writes in English but quotes a French invoice. A bilingual newsletter alternates paragraphs. A chat message switches languages mid-thought.
The sentence view checks each sentence separately and colours it by language. Sentences in a different language from the main one are shaded, and a legend shows the share of each language in the whole text. Set a minimum number of words so that very short sentences such as "Thanks!" are marked as too short instead of guessed. Export the sentence list as CSV to process it in a spreadsheet.
Why it sometimes gets it wrong
- Short texts. Three words rarely contain enough evidence.
- Close relatives. Czech and Slovak, Indonesian and Malay, Croatian, Serbian and Bosnian in Latin letters share most common words.
- Names, numbers and code. They carry no language information.
- Romanised text. Hindi or Arabic typed in Latin letters looks like an unknown Latin-script language.
For the best results, give the detector at least one full sentence, and check the runner-up list when the confidence is low.
Practical uses
Support inboxes. Paste a message and send it to the team that speaks the language, or pick the right reply template.
Web pages. Check that the lang attribute in your HTML matches the actual content, especially on pages assembled from several sources.
Survey answers. Run open answers through the sentence view to see how many were written in each language before you plan translation.
Language learning. Check whether a paragraph you wrote is clearly recognised as the target language; a low score often means many borrowed words.
Privacy
Both engines run on your device. The text you paste is not sent to any server, which matters for customer messages and internal documents.


&c=%23c2410c&k=education)
