Detect Language of Text in Python

Sure, I’ve worked quite a bit with language detection in Python, and a reliable library I often use is langdetect. It’s straightforward and gets the job done.

Here’s a quick example:

from langdetect import detect

text = "Ein, zwei, drei, vier"
lang = detect(text)
print(lang)  # Output: 'de' (German)

Just feed it some text, and it will return the detected language code. Perfect for simple use cases where you want to detect language quickly!