Language Detector and Translator APIs: Client-Side Detection and Translation
How browser Language Detector and Translator APIs work together, including model download, limits, extension APIs, and fallbacks.
This page summarises Chrome built-in AI documentation on identifying and translating user text in the browser. Most of the cluster centres on the Language Detector API and Translator API (Chrome 138 on desktop; Edge 148). Related material covers chrome.i18n in extensions and server-side translation with Workers AI as an alternative when on-device APIs are unavailable.
Why use client-side language detection and translation
Section titled “Why use client-side language detection and translation”Traditional translation sends text to a cloud service, runs the model on a server, and returns the result. For ephemeral input—support chat, comments, timeline posts—that adds latency, cost, and privacy risk.
Live translate text in the browser using local AI models. Help users contribute in their first language.
— Chrome, Built-in AI
The Language Detector API is a client-side web API designed to identify the language of a given text string. By performing detection locally in the browser, it enhances user privacy and reduces the need for heavy external libraries or costly server-side calls.
— Chrome, Language Detection (Modern Web Guidance)
Your website may already offer website content in multiple languages. With the Translator API, users can write in their first language. For example, users can participate in support chats in their first language, and your site can translate their message into your support agents’ first language, before the message leaves the user’s device.
— Chrome, Translation with built-in AI
Common conclusion: Detection answers “what language is this?”; translation answers “what does it say in language X?”. Pair them when the source language is unknown. Disclose automated translation to users and link to your policy when you bridge a language gap in live chat, as described in Client-side translation with AI.
Language Detector API: detect unknown input language
Section titled “Language Detector API: detect unknown input language”The Language Detector API is available from Chrome 138 stable. It ranks likely languages with confidence scores between 0.0 and 1.0.
When language detection fits your product
Section titled “When language detection fits your product”Chrome documents these situations:
- Determining the unknown source language before translation so the user does not specify both ends of the pair (Built-in AI APIs).
- Labeling text for accessibility (for example correct
langfor screen readers). - Choosing language-specific models (for example toxicity filters).
- Adjusting UI by detected input language (for example regional language variants).
Feature detection, availability, and user gesture
Section titled “Feature detection, availability, and user gesture”Run feature detection first:
if ('LanguageDetector' in self) { // The Language Detector API is available.}Call LanguageDetector.availability() before create(). The detection model may download on first use; show progress via downloadprogress on the monitor passed to LanguageDetector.create().
Run detect() and read confidence
Section titled “Run detect() and read confidence”const someUserText = 'Hallo und herzlich willkommen!';const results = await detector.detect(someUserText);for (const result of results) { console.log(result.detectedLanguage, result.confidence);}Avoid very short phrases or single words; accuracy drops sharply. Treat low confidence as unknown. The trained language set does not cover every language in the world (language detection with built-in AI).
Platform limits: The Language Detector and Translator APIs work in Chrome on desktop; they do not work on mobile devices (Get started). The API is not currently available in Web Workers. Cross-origin iframes need allow="language-detector" on the iframe.
Translator API: on-demand translation with language packs
Section titled “Translator API: on-demand translation with language packs”The Translator API is available from Chrome 138 stable for user-generated and dynamic content.
Language packs and BCP 47 codes
Section titled “Language packs and BCP 47 codes”Translation is managed with language packs, downloaded on demand. A language pack is like a dictionary for a given language.
— Chrome, Client-side translation with AI
Use BCP 47 short codes ('es', 'fr', 'en', 'zh-Hant', etc.). Pass the same sourceLanguage and targetLanguage to both Translator.availability(options) and Translator.create(options) (Translator (Modern Web Guidance)).
Translator.availability(options) returns:
| Status | Meaning |
|---|---|
available |
Language pair ready on device |
downloadable |
Supported; model must download; create() needs user gesture |
downloading |
Download in progress; create() with gesture can attach |
unavailable |
Pair or device not supported—use fallback |
Chrome reports all pairs as downloadable until a site creates a translator for a specific pair, to avoid leaking which packs are installed (Model download).
Create a translator and translate text
Section titled “Create a translator and translate text”if ('Translator' in self) { // The Translator API is supported.}
const translator = await Translator.create({ sourceLanguage: 'en', targetLanguage: 'fr', monitor(m) { m.addEventListener('downloadprogress', (e) => { console.log(`Downloaded ${e.loaded * 100}%`); }); },});
await translator.translate('Where is the next bus stop, please?');// "Où est le prochain arrêt de bus, s'il vous plaît ?"For longer text, use translateStreaming() and iterate chunks (Create and run the translator). Translations run sequentially—large batches block later requests; chunk input and show a loading state.
Access the API only via the global Translator interface; do not use the deprecated window.ai.translator namespace (API Surface).
Chrome’s implementation supports a fixed list of languages (Arabic through Chinese Traditional); the list may change—see Supported languages.
Detection plus translation: typical support-chat flow
Section titled “Detection plus translation: typical support-chat flow”A pattern from Built-in AI APIs and translate-on-device:
- User types in their first language.
LanguageDetector.detect()infers source language when unknown.Translator.create({ sourceLanguage, targetLanguage })maps to the agent’s operating language.translate()ortranslateStreaming()runs before submit, reducing delay versus page-wide translation UI.
By processing language on device, you can translate in real-time, before the user even submits the message.
— Chrome, Client-side translation with AI
Experiment with the combined flow in the playground linked from Translation with built-in AI and language detection with built-in AI.
Related APIs: extensions, writing tools, and server models
Section titled “Related APIs: extensions, writing tools, and server models”chrome.i18n in extensions (CLD)
Section titled “chrome.i18n in extensions (CLD)”Extensions use browser.i18n, not the web LanguageDetector global. getAcceptLanguages() returns the user’s accepted languages; detectLanguage(inputText) uses CLD and returns up to three languages with percentages and isReliable (chrome.i18n MV2 reference). That targets extension UI and background logic, not the same surface as built-in AI on ordinary web pages.
Writer, Rewriter, and Proofreader
Section titled “Writer, Rewriter, and Proofreader”Built-in AI APIs group translation with writing helpers: generate text (Writer API), change tone or length (Rewriter API), and fix grammar (Proofreader API). They share the same broad pattern—availability(), user-activated create(), optional model download—not the detect-then-translate pipeline.
Server-side LLM translation (Workers AI)
Section titled “Server-side LLM translation (Workers AI)”When browsers lack built-in translation, you can call hosted text models. Cloudflare’s how to choose a text generation model shows prompt-style translation across models; quality and latency vary, and informal “locales” (slang, accent mimicry) are unreliable compared to structured language-pair APIs. That path sends text to your infrastructure—different privacy and cost trade-offs than on-device APIs.
Hybrid on-device and cloud (Firebase AI Logic)
Section titled “Hybrid on-device and cloud (Firebase AI Logic)”Hybrid AI prompting with Firebase AI Logic can set mode: 'prefer_on_device' in getGenerativeModel() to use built-in AI when present and fall back to a cloud model online—useful for generative tasks, not a drop-in replacement for the dedicated Translator language-pack model.
Fallback when APIs are missing or unavailable
Section titled “Fallback when APIs are missing or unavailable”If 'LanguageDetector' or 'Translator' is absent, or availability is unavailable:
- Remote API: Server or cloud generative translation (guides mention endpoints such as Vertex AI Gemini as examples).
- Graceful degradation: Disable controls and explain that client-side detection or translation is unsupported.
- Polyfills: Community polyfills may emulate the API via remote services, which removes on-device privacy guarantees and often adds API cost (Fallback Strategy).
Common mistakes
Section titled “Common mistakes”- Calling
create()on first page load without a user gesture when the model isdownloadable. - Using different language options in
availability()andcreate()for translation. - Trusting detection on one-word input.
- Assuming mobile Chrome support for Language Detector / Translator on desktop-only docs.
- Omitting user-visible notice that messages are auto-translated in support flows.
- Embedding translation in cross-origin iframes without
allow="translator"orallow="language-detector".
How to check this on your site
Section titled “How to check this on your site”-
In desktop Chrome 138+, open your page and confirm
typeof LanguageDetector !== 'undefined'andtypeof Translator !== 'undefined'in the console, matching Get started and Get started (Translator). -
Log
await LanguageDetector.availability()and, for your pair,await Translator.availability({ sourceLanguage, targetLanguage })with the same codes you pass tocreate(). -
Trigger detection and translation from a button click; verify
downloadprogressif status wasdownloadable, then run sample text throughdetect()andtranslate()and compare confidence and output. -
Test an unsupported environment (mobile browser or older desktop) and confirm your UI falls back without uncaught errors, per Fallback Strategy.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.