v157 · built-in ai · android
Language Detector API on Android
Detect the language of a piece of text on-device, with confidence scores. This page probes
both routes the platform exposes — LanguageDetector.availability() and the older
translation.canDetect() — reports the raw values it gets, and labels every result
with whether it came from the model or from the page's own fallback.
concepts
Five hands-on pages for the Android-specific questions: is the model on this phone, what does it cost to get it, what exactly does detect() return, how does it refuse, and how does it compose with the Translator API on Android (v161). None of them downloads a model unless you press a button that says it will.
-
Availability & expected languages
The basic call. Read the raw
LanguageDetector.availability()value with and withoutexpectedInputLanguages, sweep yournavigator.languagesone tag at a time, and see Chromium's supported-language list and theRangeErrorfor invalid tags. -
Download on a constrained device
An inspection tool that combines connection type, Save-Data,
deviceMemory, storage and online state with availability to decide: detect now, ask first, or wait. The download only starts on your tap, with a<progress>bar fed bydownloadprogress, plus cancel, retry anddestroy(). -
Confidence inspector
The raw ranked array from
detect(), checked against Chromium's rules (descending order, trailingund, sum of 1,iw→he), plus a length ramp showing how short phone messages lose confidence, andinputQuota/measureInputUsage(). -
Failure & policy gates
Every refusal run for real: invalid tag, unsupported language, aborted signal, an iframe denied
language-detector, no user gesture, secure-context and worker exposure, and what we found (and didn't find) about enterprise policy. -
Detect-then-translate composer
A practical phone-first chat reply box: detect the language you wrote in, then translate with
Translatoronly if the pack is already installed. Low-confidence or missing-model messages are sent untranslated and labelled. Enter-to-send is IME-safe.
what the browser reports
detect a language
the code
// Probe first — never assume.
const availability = typeof LanguageDetector?.availability === "function"
? await LanguageDetector.availability()
: "unknown";
const usable = ["available", "downloadable", "downloading"].includes(availability);
if (usable) {
const detector = await LanguageDetector.create();
const results = await detector.detect("Bonjour le monde");
// [{ detectedLanguage: "fr", confidence: 0.99 }, ...]
}
// The older surface, still worth probing for compatibility:
const canDetect = typeof translation?.canDetect === "function"
? await translation.canDetect()
: "unknown";
what is Android-specific here
The API surface is not Android-only: LanguageDetector is the same JavaScript
object wherever it is exposed. The Android listing tracks when the on-device model becomes
available on Android builds, which is why this page is laid out for a phone viewport first and
why it reports model availability instead of assuming it. On any platform the honest sequence
is the same: probe, then use the model only if the probe said it is usable, and label results
that came from your own fallback.
see also
- Language Detector API — canonical feature demos
- ChromeStatus entry (Android listing)
- Chrome built-in AI docs
- Spec — Language Detector API