Translator: availability() static method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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 availability() static method of the Translator interface returns an enumerated value that indicates the availability of the AI model for the given Translator configuration.

Syntax

js
Translator.availability(options)

Parameters

options

An object specifying configuration options for the Translator. Possible values include:

sourceLanguage

A string specifying the language of the input text to be translated, which should be a valid BCP 47 language tag.

targetLanguage

A string specifying the language that the input text will be translated into, which should be valid BCP 47 language tag.

Return value

A Promise that fulfills with an enumerated value indicating whether support is available (or will be available) for a given Translator configuration, or null if support could not be determined.

Possible values include:

available

The browser supports the given configuration and it can be used immediately.

downloadable

The browser supports the given configuration, but it first needs to download an AI model, or some fine-tuning data for the model.

downloading

The browser supports the given configuration, but it has to finish an ongoing download before it can proceed.

unavailable

The browser does not support the given configuration. This value is also returned if the specified sourceLanguage and targetLanguage are the same.

Exceptions

InvalidStateError DOMException

Thrown if the page's Document is not yet active.

OperationError DOMException

Thrown if initialization of the AI model failed for any reason.

UnknownError DOMException

Thrown if the availability() call failed for any other reason, or a reason the user agent did not wish to disclose.

If usage of the method is blocked by a translator Permissions-Policy, the promise rejects with a value of unavailable.

Examples

Basic availability() usage

In the following snippet, we start by checking the availability of the model for translating between two languages using the availability() method:

  • If it returns unavailable, we print an appropriate error message to the console.
  • If it returns available, we create a translator using the create() method, passing it the source and target languages. The required AI model is available, so we can use it immediately.
  • If it returns a different value (that is, downloadable or downloading), we run the same create() method call, but this time we include a monitor that logs the percentage of the model downloaded each time the downloadprogress event fires.
js
async function getTranslator(languages) {
  const availability = await Translator.availability(languages);

  if (availability === "unavailable") {
    console.log(
      `Translation not supported; try a different language combination.`,
    );
    return undefined;
  } else if (availability === "available") {
    return await Translator.create(languages);
  }
  return await Translator.create({
    ...languages,
    monitor(monitor) {
      monitor.addEventListener("downloadprogress", (e) => {
        console.log(`Downloaded ${Math.floor(e.loaded * 100)}%`);
      });
    },
  });
}

const translator = await getTranslator({
  sourceLanguage: "en",
  targetLanguage: "ja",
});

Detecting language support

js
async function langSupport(source, target) {
  const availability = await Translator.availability({
    sourceLanguage: source,
    targetLanguage: target,
  });
  return availability;
}

await langSupport("en", "fr");
await langSupport("en", "pt");
await langSupport("en", "zh");

Specifications

Specification
Translator and Language Detector APIs
# dom-translator-availability

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
availability() static method
Experimental
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote
footnote Availability may be subject to geographical restrictions.
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote
footnote Availability may be subject to geographical restrictions.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

See also