Translate posts (in bulk) from the "Classic editor"

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

This query translates multiple "Classic editor" posts at once (in bulk), while executing a single call to the Google Translate API containing all text to translate from all the posts.

This query requires the endpoint to have Nested Mutations enabled.

query FetchData($postIds: [ID!]!)
{
posts(filter: { ids: $postIds, status: any } ) {
title
rawContent
rawExcerpt
@export(
as: "dataToTranslate",
affectAdditionalFieldsUnderPos: [1, 2]
type: DICTIONARY
)
}
}

query TranslateData(
$toLang: String!
)
@depends(on: "FetchData")
{
translatedData: _echo(value: $dataToTranslate)
@underEachJSONObjectProperty
@underEachJSONObjectProperty
@strTranslate(to: $toLang)
@export(as: "translatedData")
}

query GenerateMutationInputs
@depends(on: "TranslateData")
{
postInputs: _echo(value: $translatedData)
@underEachJSONObjectProperty(
passValueOnwardsAs: "postTranslatedData"
affectDirectivesUnderPos: [1, 2, 3, 4]
)
@applyField(
name: "_objectProperty",
arguments: {
object: $postTranslatedData,
by: {
key: "title",
}
},
passOnwardsAs: "postTranslatedTitle"
)
@applyField(
name: "_objectProperty",
arguments: {
object: $postTranslatedData,
by: {
key: "rawExcerpt",
}
},
passOnwardsAs: "postTranslatedRawExcerpt"
)
@applyField(
name: "_objectProperty",
arguments: {
object: $postTranslatedData,
by: {
key: "rawContent",
}
},
passOnwardsAs: "postTranslatedRawContent"
)
@applyField(
name: "_echo",
arguments: {
value: {
title: $postTranslatedTitle,
excerpt: $postTranslatedRawExcerpt,
contentAs: {
html: $postTranslatedRawContent
}
}
},
setResultInResponse: true
)
@export(as: "postInputs")
}

mutation TranslateClassicEditorPosts($postIds: [ID!]!)
@depends(on: "GenerateMutationInputs")
{
updatePosts: posts(filter: { ids: $postIds, status: any } ) {
id
postInput: _objectProperty(
object: $postInputs,
by: {
key: $__id
}
)
@remove
update(input: $__postInput) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
rawExcerpt
rawContent
}
}
}
}

Extensions required for this query permalink

  1. Field on Field permalink

    Manipulate the value of a field by applying some other field on it.

  2. Field Response Removal permalink

    Remove the output of a field from the response.

  3. Field To Input permalink

    Retrieve the value of a field, manipulate it, and input it into another field or directive, all within the same operation.

  4. Field Value Iteration and Manipulation permalink

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

  5. Google Translate permalink

    Translate content to multiple languages using the Google Translate API.

  6. Multiple Query Execution permalink

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

  7. 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