Queries LibraryTranslate Bricks content
Translate Bricks content
This query translates the content in the heading
, text
, text-basic
, button
and dropdown
elements of a Bricks page to a different language.
This query requires the Bricks extension and the Translation extension to be enabled.
The query requires the following variables:
$customPostId
: The ID of the Bricks custom post to update$targetLanguageCode
: The language code to translate the content to (e.g., "es", "fr", "de")
query InitializeGlobalVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
emptyArray: _echo(value: [])
@export(as: "elementToUpdateIDs")
@export(as: "elementToUpdateTexts")
@remove
}
query GetAndTranslateBricksData(
$customPostId: ID!
$targetLanguageCode: String!
)
@depends(on: "InitializeGlobalVariables")
{
customPost(by:{ id: $customPostId }, status: any) {
id
title
bricksData(filterBy: { include: [
"heading",
"text",
"text-basic",
"button",
"dropdown",
] })
@underEachArrayItem(
affectDirectivesUnderPos: [1, 3]
)
@underJSONObjectProperty(by: { key: "id" })
@export(as: "elementToUpdateIDs")
@underJSONObjectProperty(
by: { path: "settings.text" }
affectDirectivesUnderPos: [1, 2]
)
@strTranslate(to: $targetLanguageCode)
@export(as: "elementToUpdateTexts")
}
}
query GetElementToUpdateData
@depends(on: "GetAndTranslateBricksData")
{
elementToUpdateMergeInputElements: _echo(value: $elementToUpdateTexts)
@underEachArrayItem(
passIndexOnwardsAs: "index",
passValueOnwardsAs: "elementToUpdateText"
affectDirectivesUnderPos: [1, 2]
)
@applyField(
name: "_arrayItem",
arguments: {
array: $elementToUpdateIDs,
position: $index
},
passOnwardsAs: "elementToUpdateID"
)
@applyField(
name: "_echo",
arguments: {
value: {
id: $elementToUpdateID,
settings: {
text: $elementToUpdateText
}
}
}
setResultInResponse: true
)
@export(as: "elementToUpdateMergeInputElements")
}
mutation StoreUpdatedElementText($customPostId: ID!)
@depends(on: "GetElementToUpdateData")
{
bricksMergeCustomPostElementDataItem(input: {
customPostID: $customPostId
elements: $elementToUpdateMergeInputElements
}) {
status
errors {
__typename
...on ErrorPayload {
message
@passOnwards(as: "message")
@fail(
message: $message
condition: ALWAYS
)
}
}
customPost {
__typename
...on CustomPost {
id
bricksData
}
}
}
}