Bibliothèque de queriesTraduire un article depuis le "Classic editor"
Traduire un article depuis le "Classic editor"
Cette requête traduit un article du "Classic editor" dans la langue souhaitée.
En fonction du paramètre $update, la traduction sera enregistrée sous le même article ou comme un nouvel article.
########################################################################
#
# Variables:
# - postId: ID of the post to translate
# - toLang: The language code to translate to, from Google Translate (https://cloud.google.com/translate/docs/languages)
# - update: Indicate if to update the post, or create a new one
#
# *********************************************************************
#
# === Description ===
#
# This Persisted GraphQL query translates a "Classic editor" post to
# the desired language.
#
# Depending on the `$update` parameter, the translation will either
# be saved as:
#
# - false (default): A new post (using the translated slug) with "draft" status
# - true: The same post
#
########################################################################
query InitializeVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
isGutenbergEditorEnabled
@export(as: "isGutenbergEditorEnabled")
}
query FetchData($postId: ID!)
@depends(on: "InitializeVariables")
@skip(if: $isGutenbergEditorEnabled)
{
post(by: { id: $postId }, status: any) {
title
rawContent
rawExcerpt
@export(
as: "dataToTranslate",
affectAdditionalFieldsUnderPos: [1, 2]
)
}
}
query TranslateData(
$toLang: String!
)
@depends(on: "FetchData")
@skip(if: $isGutenbergEditorEnabled)
{
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")
@skip(if: $isGutenbergEditorEnabled)
{
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
}
}
}