Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. LanguageDetector

LanguageDetector

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

TheLanguageDetector interface of theTranslator and Language Detector APIs contains all the language detection functionality, including checking AI model availability, creating a newLanguageDetector instance, using it to detect a language, and more.

Instance properties

inputQuotaRead onlyExperimental

The input quota available to the browser for detecting languages.

expectedInputLanguagesRead onlyExperimental

The expected languages to be detected in the input text.

Static methods

availability()Experimental

Returns an enumerated value that indicates whether the browser AI model supports a givenLanguageDetector configuration.

create()Experimental

Creates a newLanguageDetector instance to detect languages.

Instance methods

destroy()Experimental

Destroys theLanguageDetector instance it is called on.

detect()Experimental

Detects the closest matching language or languages that a given text string is most likely to be written in.

measureInputUsage()Experimental

Reports how much input quota would be used by a language detection operation for a given text input.

Examples

SeeUsing the Translator and Language Detector APIs for a complete example.

Creating aLanguageDetector instance

js
const detector = await LanguageDetector.create({  expectedInputLanguages: ["en-US", "zh"],});

Note:Different implementations will likely support different languages.

Detecting languages

js
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

Specification
Translator and Language Detector APIs
# languagedetector

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp