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.
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