demo · v130

Confidence budget

detector.detect(text) returns ranked {detectedLanguage, confidence} entries. The right product behaviour depends on a threshold: too low and you mis-translate; too high and you nag the user. Dial in your own budget here against six representative inputs (one word, transliteration, code-switch, etc.) and see exactly which inputs three different product strategies would handle, ask about, or skip.

requires the Built-in AI / Language Detection flag Enable chrome://flags/#language-detection-api (Chrome 130+) or join the Built-in AI origin trial. Without the API, the page falls back to a character-script heuristic so the budget controls still demonstrate the trade-off.

six representative inputs

three product strategies, all six inputs

Strategy A — Auto-translate

If top confidence ≥ threshold AND top language ≠ user's UI lang, translate silently.

Strategy B — Suggest, never act

If top confidence ≥ threshold, show a banner "translate?". Below threshold: silence.

Strategy C — Two-tier

≥0.9 silent translate. 0.5–0.9 ask. Below 0.5: skip silently.

the code

const d = await LanguageDetector.create();
const ranked = await d.detect(text);
// ranked: [{ detectedLanguage: "fr", confidence: 0.83 }, …]

const top = ranked[0];
if (top.confidence >= 0.9) {
  translateSilently(text, top.detectedLanguage);
} else if (top.confidence >= 0.5) {
  showBanner(`Translate from ${top.detectedLanguage}?`);
} else {
  /* skip — the model isn't confident enough to act */
}

see also