Translate a post from the "Classic editor"

🔥 This query is already included in Gato GraphQL, as Persisted Query “Translate post (Classic editor)”.

This query translates a "Classic editor" post to the desired language.

Depending on the $update parameter, the translation will either be saved under the same post, or as a new post.

query FetchData($postId: ID!)
{
post(by: { id: $postId }, status: any) {
title
rawContent
rawExcerpt
@export(
as: "dataToTranslate",
affectAdditionalFieldsUnderPos: [1, 2]
)
}
}

query TranslateData(
$toLang: String!
)
@depends(on: "FetchData")
{
translations: _echo(value: $dataToTranslate)
@underEachJSONObjectProperty
@strTranslate(to: $toLang)
@underJSONObjectProperty(by: { key: "title" })
@export(as: "translatedTitle")
@underJSONObjectProperty(by: { key: "rawContent" })
@export(as: "translatedRawContent")
@underJSONObjectProperty(by: { key: "rawExcerpt" })
@export(as: "translatedRawExcerpt")
}

mutation TranslateClassicEditorPost(
$postId: ID!
$update: Boolean! = false
)
@depends(on: "TranslateData")
{
createPost(input: {
title: $translatedTitle,
contentAs: {
html: $translatedRawContent
},
excerpt: $translatedRawExcerpt,
status: draft
})
@skip(if: $update)
{
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
slug
rawContent
rawExcerpt
}
}

updatePost(input: {
id: $postId,
title: $translatedTitle,
contentAs: {
html: $translatedRawContent
},
excerpt: $translatedRawExcerpt
})
@include(if: $update)
{
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
rawContent
rawExcerpt
}
}
}

Extensions required for this query permalink

  1. Field Value Iteration and Manipulation permalink

    Iterate and manipulate the value elements of array and object fields.

  2. Google Translate permalink

    Translate content to multiple languages using the Google Translate API.

  3. Multiple Query Execution permalink

    Combine multiple queries into a single query, sharing state across them and executing them in the requested order.

  4. PHP Functions via Schema permalink

    Manipulate the field output using standard programming language functions available in PHP.

Bundles containing all extensions required for this query permalink

  1. “All in One Toolbox for WordPress” Bundle permalink

    Achieve all superpowers: All of Gato GraphQL extensions, in a single plugin

  2. “Automated Content Translation & Sync for WordPress Multisite” Bundle permalink

    Automatically create a translation of a newly-published post using the Google Translate API, for every language site on a WordPress multisite

  3. “Simplest WordPress Content Translation” Bundle permalink

    Translate your content into over 130 languages using the Google Translate API, without adding extra tables or inner joins to the DB