v148 · AI · JavaScript

Language Detector API

Detect the language of any text entirely on-device using Chrome's built-in ML model. No API key, no network round-trip, no privacy exposure — the inference runs locally in the browser.

concepts

  1. Language Sniffer

    Type or paste any text and watch the detector return a ranked list of language candidates with confidence scores, all computed on-device via LanguageDetector.create().

  2. Multilingual Sorter

    Enter a list of sentences in different languages and the sorter groups them by detected language — demonstrating how you might automatically route multilingual user content.

  3. Content Router

    Route content to language-appropriate handlers using LanguageDetector.detect(). Type or paste text — the on-device model identifies the language and routes to the matching locale handler, with a live confidence bar and a highlighted routing table row.

  4. Live Language Badge

    A compose box that detects language as you type and shows a live badge with confidence score. When non-English text is detected, a "Translate to English" hint bar appears — exactly how a real email client or social compose UI would work. Seven sample snippets plus free-form typing.

  5. Confidence Meter

    Visualises the top 3 language candidates as percentage bars that update live as you type — revealing when text is genuinely ambiguous (near-equal scores) versus unambiguous (one language at 90%+). Includes 8 sample texts and a heuristic Unicode-range fallback when the Language Detector API is unavailable.

  6. Local Triage Workflow

    A realistic multilingual support triage flow: submit a message in any language, the on-device Language Detector identifies it, and the ticket is routed to the correct regional team. Zero text leaves the browser.

  7. Quality Control Panel

    Benchmark the Language Detector API against a heuristic fallback on 10 diverse text samples. Runs each in sequence and reports per-detection latency, confidence scores, and whether the real API or the fallback fired.

  8. Safety Harness

    A 12-case edge-case test suite: API availability, empty input, emoji-only text, numbers, mixed scripts, very long text, and recovery from model-unavailable states. Run all or individual tests with pass/warn/fail reporting.

why it shipped

Language detection is a prerequisite for many web features: routing multilingual user input, applying locale-specific formatting, triggering the right spell-checker, or deciding whether to offer a translation. Cloud-based detection adds latency and sends potentially sensitive text to a server. Chrome 138 ships LanguageDetector — part of the built-in AI API suite — with availability() for model readiness, on-demand model download when needed, and detect(text) returning an ordered array of { detectedLanguage, confidence } results.

references

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗