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.
Checks if the user agent can support translating between the specified sourceLanguage and targetLanguage.
staticavailability(options: TranslatorCreateCoreOptions): Promise<Availability>; | Property | Type | Description |
|---|---|---|
| sourceLanguage | DOMString | Required A BCP 47 language tag identifying the source language (e.g., 'en', 'ja'). |
| targetLanguage | DOMString | Required A BCP 47 language tag identifying the target language. |
A promise that resolves to an Availability string: 'available', 'downloadable', 'downloading', or 'unavailable'.
Instantiates a new Translator object, initiating any necessary model or language pack downloads.
staticcreate(options: TranslatorCreateOptions): Promise<Translator>; | Property | Type | Description |
|---|---|---|
| sourceLanguage | DOMString | Required The source language code (e.g. 'en'). |
| targetLanguage | DOMString | Required The target language code (e.g. 'fr'). |
| signal | AbortSignal | Allows aborting the creation and download process. |
| monitor | CreateMonitorCallback | Callback to listen to downloadprogress events. |
Translates the given input string from the configured source language to the target language.
translate(input: DOMString, options?: TranslatorTranslateOptions): Promise<DOMString>; | Property | Type | Description |
|---|---|---|
| input | DOMString | The string to translate. |
| options.signal | AbortSignal | Optional signal to abort the translation request. |
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; 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>; 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; | Property | Type | Description |
|---|---|---|
| sourceLanguage | DOMString (readonly) | The canonicalized BCP 47 language tag of the source language. |
| targetLanguage | DOMString (readonly) | The canonicalized BCP 47 language tag of the target language. |
| inputQuota | unrestricted 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. |