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 create() static method of the Translator interface creates a new Translator instance that can be used to translate text.
Note: The create() method requires transient activation, that is, it must be invoked in response to a user action such as a mouse click or button press.
Translator.create(options)optionsAn object specifying configuration options for the Translator. Possible values include:
sourceLanguageA string specifying the expected language of the input text to be translated, which should be a valid BCP 47 language tag.
targetLanguageA string specifying the language that the input text will be translated into, which should be valid BCP 47 language tag.
monitor OptionalA callback function with a CreateMonitor argument that enables monitoring download progress of the AI model.
signal OptionalAn AbortSignal object instance, which allows a create() operation to be aborted via the associated AbortController. The exact effect is dependent on when AbortController.abort() is called:
abort() is called before the create() promise resolves, the create() operation is cancelled.abort() is called after the create() promise fulfills, it has the same effect as calling Translator.destroy(): The resources assigned to the resulting Translator instance are released, and any ongoing and subsequent Translator method calls will reject with an AbortError.A Promise that fulfills with a Translator object instance.
InvalidStateError DOMExceptionThrown if the page's Document is not yet active.
NetworkError DOMExceptionThrown if:
NotAllowedError DOMExceptionThrown if:
translator Permissions-Policy.create() method wasn't called via transient activation.NotSupportedError DOMExceptionThrown if:
sourceLanguage or targetLanguage are invalid, or not supported. This is the case if the specified sourceLanguage and targetLanguage are the same.sourceLanguage and targetLanguage is not available.OperationError DOMExceptionGeneral-purpose exception thrown if Translator creation failed for any other reason.
Translator creationconst translator = await Translator.create({
sourceLanguage: "en",
targetLanguage: "ja",
});