The Language Detector API identifies the most likely language a given text is written in, returning ranked BCP 47 language tags with confidence scores — on-device.
Checks if the user agent can support language detection. If expectedInputLanguages is provided, it specifically checks if those languages are supported.
staticavailability(options?: LanguageDetectorCreateCoreOptions): Promise<Availability>; | Property | Type | Description |
|---|---|---|
| expectedInputLanguages | sequence<DOMString> | Optional An array of BCP 47 language tags that the application expects to detect. |
A promise resolving to 'available', 'downloadable', 'downloading', or 'unavailable'.
Instantiates a new LanguageDetector object, initiating any necessary model downloads.
staticcreate(options?: LanguageDetectorCreateOptions): Promise<LanguageDetector>; | Property | Type | Description |
|---|---|---|
| expectedInputLanguages | sequence<DOMString> | Optional Helps the user agent download specific models necessary to support these languages. |
| signal | AbortSignal | Optional Allows aborting the creation and download process. |
| monitor | CreateMonitorCallback | Optional Callback to listen to downloadprogress events. |
Detects the language of the input string. Returns an array of candidate results sorted in descending order of confidence. Extremely low confidence results are excluded. The final entry in the array is always for the undetermined language ('und').
detect(input: DOMString, options?: LanguageDetectorDetectOptions): Promise<sequence<LanguageDetectionResult>>; | Property | Type | Description |
|---|---|---|
| input | DOMString | The string to analyze. |
| options.signal | AbortSignal | Optional Signal to abort the detection request. |
A promise that resolves to an array of objects containing detectedLanguage (a BCP 47 string) and confidence (a double between 0 and 1).
Calculates how much quota the string would consume without executing the detection. If this returns a value greater than inputQuota, the returned promise will reject with a QuotaExceededError.
measureInputUsage(input: DOMString, options?: LanguageDetectorDetectOptions): Promise<double>; Destroys the language detector instance, aborting any active requests and allowing the browser to unload the underlying machine learning models from memory.
destroy(): undefined; | Property | Type | Description |
|---|---|---|
| expectedInputLanguages | FrozenArray<DOMString> | null (readonly) | The array of languages expected to be detected, provided during creation. |
| inputQuota | unrestricted double (readonly) | The maximum input usage allowed per detection operation. Can be +Infinity if the implementation imposes no input limit (e.g. because it processes input in chunks); in that case measureInputUsage() always returns 0. |