The Translator API translates text between languages using the browser's built-in translation capabilities. In Chrome, translation runs on-device, preserving privacy and enabling offline usage.

Translator.availability()

Checks if the user agent can support translating between the specified sourceLanguage and targetLanguage.

staticavailability(options: TranslatorCreateCoreOptions): Promise<Availability>;

Parameters (TranslatorCreateCoreOptions)

PropertyTypeDescription
sourceLanguageDOMStringRequired
A BCP 47 language tag identifying the source language (e.g., 'en', 'ja').
targetLanguageDOMStringRequired
A BCP 47 language tag identifying the target language.

Returns

A promise that resolves to an Availability string: 'available', 'downloadable', 'downloading', or 'unavailable'.

Interactive Playground

Translator.create()

Instantiates a new Translator object, initiating any necessary model or language pack downloads.

staticcreate(options: TranslatorCreateOptions): Promise<Translator>;

Parameters (TranslatorCreateOptions)

PropertyTypeDescription
sourceLanguageDOMStringRequired
The source language code (e.g. 'en').
targetLanguageDOMStringRequired
The target language code (e.g. 'fr').
signalAbortSignalAllows aborting the creation and download process.
monitorCreateMonitorCallbackCallback to listen to downloadprogress events.
Interactive Playground

translator.translate()

Translates the given input string from the configured source language to the target language.

translate(input: DOMString, options?: TranslatorTranslateOptions): Promise<DOMString>;

Parameters

PropertyTypeDescription
inputDOMStringThe string to translate.
options.signalAbortSignalOptional signal to abort the translation request.
Interactive Playground

translator.translateStreaming()

Returns a ReadableStream that yields the translated string in chunks as it's generated. Chunk timing is implementation-defined; chunks may not arrive at a steady rate.

translateStreaming(input: DOMString, options?: TranslatorTranslateOptions): ReadableStream;
Interactive Playground

translator.measureInputUsage()

Calculates how much quota the translation string would consume without executing the translation. If this returns a value greater than inputQuota, translating it will reject with a QuotaExceededError (whose requested and quota properties help you build UX around the limit).

measureInputUsage(input: DOMString, options?: TranslatorTranslateOptions): Promise<double>;
Interactive Playground

translator.destroy()

Destroys the translator instance, rejecting any ongoing translate() calls, erroring any streams returned by translateStreaming(), and allowing the browser to unload the underlying models from memory.

destroy(): undefined;
Interactive Playground

Properties

PropertyTypeDescription
sourceLanguageDOMString (readonly)The canonicalized BCP 47 language tag of the source language.
targetLanguageDOMString (readonly)The canonicalized BCP 47 language tag of the target language.
inputQuotaunrestricted double (readonly)The maximum input usage allowed per translation operation. Can be +Infinity if the implementation imposes no input limit (e.g. because it processes input in chunks); in that case measureInputUsage() always returns 0.