files/en-us/web/api/languagedetector/index.md
{{APIRef("Translator and Language Detector APIs")}}{{SeeCompatTable}}{{securecontext_header}}
The LanguageDetector interface of the {{domxref("Translator and Language Detector APIs", "Translator and Language Detector APIs", "", "nocode")}} contains all the language detection functionality, including checking AI model availability, creating a new LanguageDetector instance, using it to detect a language, and more.
{{InheritanceDiagram}}
LanguageDetector configuration.LanguageDetector instance to detect languages.LanguageDetector instance it is called on and stops any further activity on it.See Using the Translator and Language Detector APIs for a complete example.
LanguageDetector instanceconst detector = await LanguageDetector.create({
expectedInputLanguages: ["en-US", "zh"],
});
[!NOTE] Different implementations will likely support different languages.
const results = await detector.detect(myTextString);
results.forEach((result) => {
console.log(`${result.detectedLanguage}: ${result.confidence}`);
});
// Results in logs like this:
// la: 0.8359838724136353
// es: 0.017705978825688362
// sv: 0.012977192178368568
// en: 0.011148443445563316
{{Specifications}}
{{Compat}}