v157 · concept 1 · basic
Availability & expected languages
LanguageDetector.availability() is the cheap first call a phone page makes. It never downloads, needs no tap, and works before you know anything about the text. Passing expectedInputLanguages asks a sharper question: can the model on this device detect these languages? This page sends both versions and shows the raw value each one returned.
LanguageDetector is exposed…ask about specific languages
Try ja-Latn (romanised Japanese, supported), kl (not in Chromium's list), or not a tag! (invalid).
one call per language
Some languages are supported and some aren't, so a single unavailable for a list doesn't tell you which one caused it. This sweep calls availability() once for each tag in the box above, then once more with the whole list.
| expectedInputLanguages | Raw value | What it means |
|---|---|---|
| Not checked yet. | ||
what the four values mean on a phone
- available: the detection model is already on the device.
create()works without a tap, and works offline. - downloadable: Chrome can fetch the model, but
create()must run inside a tap (Chromium rejects withNotAllowedError: “Requires a user gesture when availability is "downloading" or "downloadable"”). On a phone, tell people before the tap that the download will use data. - downloading: a download is already running. Attaching to it still needs a tap.
- unavailable: the model can't run here, one of the expected languages isn't in the model's list, or the frame isn't allowed the
language-detectorpermissions-policy feature.availability()alone can't tell you which. See Failure & policy gates.
Languages Chromium accepts in expectedInputLanguages
Copied from kSupportedLanguages in third_party/blink/renderer/modules/ai/on_device_translation/language_detector.cc. A tag outside this list makes availability() return unavailable and create() reject with NotSupportedError (“Language not available”). Chromium matches by best fit, so en-GB resolves to en.
the code
if (!("LanguageDetector" in self)) { /* not exposed: old build, insecure context, other browser */ }
const any = await LanguageDetector.availability();
const mine = await LanguageDetector.availability({
expectedInputLanguages: navigator.languages, // validated as BCP 47 first: bad tags throw RangeError
});
// "unavailable" here can mean "one of these languages isn't supported". Ask per language to find out which.
see also
- Download on a constrained device: what to do with
downloadable - Confidence inspector: the shape of
detect()results - Translator availability on Android (v161): the same four values for language pairs
- ChromeStatus entry (5087964794322944)
- Spec: Language Detector API