sectionTranslate
Creates a translation of a section in another locale. The translation is a new section with its own ID, linked to the source through localizedReferences. It's created as a draft; publish it with sectionPublish.
Any field you leave out of input is copied from the source, except its status and publish dates. Each locale can have one translation; translating into a locale that already has one returns an error, so use the update mutation on the translation's ID to change it.
With a content release selected (X-Pack-Release-Id), the translation is saved as a release draft and joins the source's locale group when the release publishes. To read translated content, pass language and country to the @inContext directive; see Localization.
Arguments
- Name
sourceContentId- Type
- ID!
- Description
The ID of the section to translate.
- Name
localeId- Type
- ID!
- Description
The ID of the locale to translate into, from your store's locales.
- Name
input- Type
- SectionUpsertInput!
- Description
An object with the translated values.
id:IDNot used when translating.title:Stringdata:JSONThe section's field values, shaped by its section schema.dataSource:JSONlocaleId:IDIgnored; thelocaleIdargument sets the locale.styles:JSON
Returns
- Name
Section.*- Type
- Section
- Description
Any requested field from the Section object for the new translation.
Request
import { PackClient } from '@pack/client'
const packClient = new PackClient({
token: 'YOUR-PACK-SECRET-TOKEN'
});
const query = `
mutation SectionTranslate($sourceContentId: ID!, $localeId: ID!, $input: SectionUpsertInput!) {
sectionTranslate(sourceContentId: $sourceContentId, localeId: $localeId, input: $input) {
id
title
status
locale {
languageCode
countryCode
}
}
}
`;
const variables = {
sourceContentId: 'YOUR-SOURCE-ID',
localeId: 'YOUR-LOCALE-ID',
input: {
title: 'Bannière'
}
};
const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);
Response
{
"data": {
"sectionTranslate": {
"id": "YOUR-TRANSLATED-ID",
"title": "Banni\u00e8re",
"status": "draft",
"locale": {
"languageCode": "fr",
"countryCode": "CA"
}
}
}
}