Skip to content

Instantly share code, notes, and snippets.

@KnightChaser
Created November 6, 2025 03:01
Show Gist options
  • Select an option

  • Save KnightChaser/70d1d8b72043d420da3106f7323623bd to your computer and use it in GitHub Desktop.

Select an option

Save KnightChaser/70d1d8b72043d420da3106f7323623bd to your computer and use it in GitHub Desktop.
A simple snippet to determine the language of arbitrary text string.
from langdetect import DetectorFactory, detect
from langcodes import Language
DetectorFactory.seed = 0
text = "Hello, how are you today? I hope you're doing well!"
language_code = detect(text)
language_name = Language.get(language_code).language_name('en')
print(f"Detected language code: {language_code}")
print(f"Detected language name: {language_name}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment