v148 · AI · JavaScript

Translator API

Translate text between languages entirely on-device using Chrome's built-in ML model. One Translator.create() call, one translate(text) call — no API key, no network, no privacy exposure.

concepts

  1. Live Translator

    Type text in any supported language and see the translation appear in real time. Switch source and target languages from a dropdown — all processing stays on your device.

  2. Translate Chain

    Pass a sentence through a chain of language hops — English → French → Japanese → Spanish → English — and see how the meaning evolves (or degrades) with each on-device translation step.

  3. Batch Translator

    Translate a whole list of UI strings in one go — all fired in parallel via a single Translator instance. Per-item timings show how the on-device model handles concurrent translation requests.

  4. Document Translator

    A rich document with paragraphs in five languages. "Detect languages" badges each paragraph with its language and confidence score via LanguageDetector. "Translate all to English" processes every non-English paragraph. A language pair availability checker tests which {from, to} pairs are available via Translator.availability().

  5. Language Pair Explorer

    An interactive 6×6 matrix of common language pairs (en, fr, de, ja, zh, es). Each cell is probed with capabilities.languagePairAvailable(from, to) and coloured by result — readily available, available after download, or unavailable. A swap button lets you flip source and target, and a pair selector drills into any combination.

  6. Local-First Workflow

    Three on-device translation workflows: a chat message translator with language swap, a multilingual form that translates its own labels for the user's locale, and a content review assistant that translates then sentiment-classifies user-generated content.

  7. Quality Control Panel

    Benchmark the Translator API across six language pairs simultaneously from a single source text. See per-pair latency bars, availability status (ready/needs-download/unavailable), and the translated outputs side by side.

  8. Safety Harness

    12 edge-case tests: API availability, empty input, same-source-target no-op, unsupported language pairs, very long text truncation, concurrent translation, instance reuse, consistency checks, model download triggers, invalid language codes, and graceful fallback.

why it shipped

Chrome has long shipped a built-in translation bar that translates entire pages via Google Translate. The new Translator JavaScript API gives developers direct access to the same on-device translation models, at the string level. This opens use cases like: real-time translation of user-typed chat messages, localized form validation feedback, dynamically translated help text, or automatic language matching for multilingual search. Because translation runs on-device, it works offline and doesn't expose user-typed text to any server.

references

implementation reference

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