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.

Built-in AI APIs need Chrome with the relevant flag or origin trial, and the model downloads once per profile. Nothing here claims the model is ready when it is not: the probe below shows the value the browser actually returned, and when it is not a usable value the page says so and falls back to its own heuristic detector.

what the browser reports

checking…

detect a language

No detection run yet.

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