Skip to content

getAvailableTranslations

function getAvailableTranslations(document): string[] | undefined;

Defined in: packages/json-api-client/src/getAvailableTranslations.ts:27

Extracts the translations advertised by a language-selection error.

A backend that selects translations strictly by langCode (the jsonapi_multilingual module) answers an individual read of a missing translation with 404 Not Found and lists the translations the requesting user may view as meta.availableTranslations on the error object. Use this on the parsed error document (or rawResponse json) to retry with a language that exists or to render a language switcher — or opt into the site’s fallback chain up front with the includeFallback read option.

unknown

A parsed JSON:API document, typically an error document.

string[] | undefined

The advertised langcodes, or undefined when the document does not carry them (not an error document, or a backend without the feature).

const { response, json } = await client.getResource(type, id, {
locale: "fr",
rawResponse: true,
});
if (response.status === 404) {
const available = getAvailableTranslations(json);
}