Language Recognition
Detect the dominant language of a string or rank candidate languages by confidence.
Functions
NaturalLanguage.dominantLanguage(text: string): Language | null
Return the single most likely language for text. Returns null when the text is too short or ambiguous to classify.
NaturalLanguage.languageHypotheses(text, options?): LanguageHypothesis[]
Return up to maximumCount candidate languages sorted by confidence (descending).
options.maximumCount?: number— defaults to3.options.constraints?: Language[]— soft preference; recognizer favors candidates in this set but is not strictly limited to them.options.hints?: { [language: string]: number }— prior probabilities (BCP-47 → 0...1).
Notes
- Language identification is offline and extremely fast — feel free to call it on every keystroke if needed.
- For very short input (one or two words), the recognizer may return
nullor low confidence. Provide more context when possible.
