Lingua Language Detector is an accurate natural language detection library for Python, suitable for both short text snippets and mixed-language texts. It leverages Rust bindings for high performance and low memory consumption, supporting 75 languages offline. The current version is 2.2.0, with an active development cycle featuring regular minor and patch releases.
pip install lingua-language-detectorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to build a language detector, detect the language of a single text, and identify multiple languages within a mixed-language text. It utilizes the `Language` enum and `LanguageDetectorBuilder` to configure and create a detector instance.
Review the official documentation for `lingua-language-detector` 2.x and update code to use the new API, especially `LanguageDetectorBuilder` and `Language` enum.
Upgrade your Python environment to version 3.12 or higher.
Avoid `with_low_accuracy_mode()` for short texts or applications where high accuracy is paramount. Consider pre-filtering languages to optimize performance without sacrificing accuracy.
Be aware of potential inaccuracies when using `detect_multiple_languages_of()` on very short or ambiguous mixed texts. Test thoroughly with your specific data.
Install the module using 'pip install lingua-language-detector'.
Use 'from lingua import LanguageDetectorBuilder' instead.
Use 'LanguageDetectorBuilder.from_languages(*languages).build()' to create a detector.
Use 'detector.detect_language_of(text)' after building the detector.
Specify languages using 'LanguageDetectorBuilder.from_languages(Language.ENGLISH, Language.FRENCH, ...).build()'.