Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The Translator and Language Detector APIs provide functionality to detect the language that text is written in, and to translate text into different languages, via a browser's own internal AI model (which may differ between browsers).
Translating a body of text is a common task on today's web. Typical use cases include:
Detecting the language of a body of test is an important precursor for successful automated translation, but has other uses beyond direct translation. For example, it allows automatic UI configuration based on user text entry, ranging from updating UI and error strings, to automatically loading appropriate dictionaries for spell checking or curse word detection.
AI is well-suited to facilitating language detection and translation. The Translator and Language Detector APIs provide asynchronous (Promise-based) mechanisms for a website to detect languages and translate text via the browser's own internal AI model. This is useful and efficient because the browser handles the service, rather than the developer having to rely on the user downloading AI models, or host or pay for a cloud-based translation service.
LanguageDetector interface. A LanguageDetector object instance is created using the LanguageDetector.create() static method, then the detect() instance method is passed the text string to detect the language for.Translator interface. A Translator object instance is created using the Translator.create() static method, then the translate() instance method is passed the text string to translate.You can also cancel pending operations using an AbortController.
The Translator and LanguageDetector instances consume a lot of resources, so once you're finished with them, you are encouraged to remove them using a destroy() instance method (for example, Translator.destroy()).
See Using the Translator and Language Detector APIs for a walkthrough of how to use the APIs.
LanguageDetector Experimental
Contains all the language detection functionality, including checking AI model availability, creating a new LanguageDetector instance, using it to detect a language, and more.
Translator Experimental
Contains all the translation functionality, including checking AI model availability, creating a new Translator instance, using it to create a translation, and more.
Permissions-Policy; the language-detector directiveControls access to the language detection functionality. Where a policy specifically disallows its use, any attempts to call the LanguageDetector methods will fail with a NotAllowedError DOMException.
Permissions-Policy; the translator directiveControls access to the translation functionality. Where a policy specifically disallows its use, any attempts to call the Translator methods will fail with a NotAllowedError DOMException.
Creation of LanguageDetector and Translator objects requires that the user has recently interacted with the page (transient user activation is required).
Access to the API is also controlled via language-detector and translator Permissions-Policy directives.
For a full example, see Using the Translator and Language Detector APIs.
| Specification |
|---|
| Unknown specification> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Translator_and_Language_Detector_APIs |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
availability_static |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
create_static |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
destroy |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
inputQuota |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
measureInputUsage |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
sourceLanguage |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
targetLanguage |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
translate |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
translateStreaming |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Translator_and_Language_Detector_APIs