Back to Content Management API

blogTranslate

Creates a translation of a blog in another locale. The translation is a new blog with its own ID, linked to the source through localizedReferences. It's created as a draft; publish it with blogPublish.

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 blog to translate.

  • Name
    localeId
    Type
    ID!
    Description

    The ID of the locale to translate into, from your store's locales.

  • Name
    input
    Type
    BlogInput!
    Description

    An object with the translated values.

    • title: String
    • handle: String
    • firstPublishedAt: DateTime
    • firstPublishedAtTimezone: String
    • description: String
    • seo: SEOInput
    • template: String The title of the template to attach.
    • templateId: ID The ID of the template to attach.
    • sectionIds: [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: JSON Section overrides for this content, as JSON.

Returns

  • Name
    Blog.*
    Type
    Blog
    Description

    Any requested field from the Blog object for the new translation.

Request

import { PackClient } from '@pack/client'
const packClient = new PackClient({
  token: 'YOUR-PACK-SECRET-TOKEN'
});

const query = `
  mutation BlogTranslate($sourceContentId: ID!, $localeId: ID!, $input: BlogInput!) {
    blogTranslate(sourceContentId: $sourceContentId, localeId: $localeId, input: $input) {
      id
      title
      status
      locale {
        languageCode
        countryCode
      }
    }
  }
`;

const variables = {
  sourceContentId: 'YOUR-SOURCE-ID',
  localeId: 'YOUR-LOCALE-ID',
  input: {
    title: 'Journal'
  }
};
const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);

Response

{
    "data": {
        "blogTranslate": {
            "id": "YOUR-TRANSLATED-ID",
            "title": "Journal",
            "status": "draft",
            "locale": {
                "languageCode": "fr",
                "countryCode": "CA"
            }
        }
    }
}

Was this page helpful?