articleTranslate
Creates a translation of a article in another locale. The translation is a new article with its own ID, linked to the source through localizedReferences. It's created as a draft; publish it with articlePublish.
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.
Fails while a content release is selected (X-Pack-Release-Id). To read translated content, pass language and country to the @inContext directive; see Localization.
Arguments
- Name
sourceContentId- Type
- ID!
- Description
The ID of the article to translate.
- Name
localeId- Type
- ID!
- Description
The ID of the locale to translate into, from your store's locales.
- Name
input- Type
- ArticleInput!
- Description
An object with the translated values.
title:Stringhandle:StringblogId:StringThe ID of the blog the article belongs to.description:Stringauthor:Stringcategory:Stringtags:[String!]excerpt:StringbodyHtml:Stringseo:SEOInputsectionIds:[ID!]The sections for the translation, in order. Each section that already has a translation in this locale is swapped for it. If you leave this out, the translation uses the source's sections.sectionOverrides:JSONSection overrides for this content, as JSON.template:StringThe title of the template to attach.templateId:IDThe ID of the template to attach.firstPublishedAt:DateTimefirstPublishedAtTimezone:String
Returns
- Name
Article.*- Type
- Article
- Description
Any requested field from the Article object for the new translation.
Request
import { PackClient } from '@pack/client'
const packClient = new PackClient({
token: 'YOUR-PACK-SECRET-TOKEN'
});
const query = `
mutation ArticleTranslate($sourceContentId: ID!, $localeId: ID!, $input: ArticleInput!) {
articleTranslate(sourceContentId: $sourceContentId, localeId: $localeId, input: $input) {
id
title
status
locale {
languageCode
countryCode
}
}
}
`;
const variables = {
sourceContentId: 'YOUR-SOURCE-ID',
localeId: 'YOUR-LOCALE-ID',
input: {
title: 'Notre histoire'
}
};
const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);
Response
{
"data": {
"articleTranslate": {
"id": "YOUR-TRANSLATED-ID",
"title": "Notre histoire",
"status": "draft",
"locale": {
"languageCode": "fr",
"countryCode": "CA"
}
}
}
}