Created
November 6, 2025 03:01
-
-
Save KnightChaser/70d1d8b72043d420da3106f7323623bd to your computer and use it in GitHub Desktop.
A simple snippet to determine the language of arbitrary text string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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