Gato GraphQL + Bricks Builder + Translation demosu
Bricks içeriğini çevirme
Bir Bricks sayfasındaki metin içeriğini belirtilen dile çevirir

Gato GraphQL'i Bricks eklentisi ve Translation eklentisi ile birlikte kullanarak Bricks sayfa öğelerindeki içeriği farklı dillere otomatik olarak çevirebiliriz.
Bu query, bir Bricks sayfasının heading, text, text-basic, button ve dropdown öğelerindeki içeriği başka bir dile çevirir.
Aşağıdaki değişkenleri sağlamamız gerekir:
customPostId: Güncellenecek Bricks custom post'unun ID'sitargetLanguageCode: İçeriğin çevrileceği dil kodu (örneğin, "es", "fr", "de")
GraphQL query'si şu şekildedir:
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
}
}
}
}Değişkenler şu şekilde görünecektir:
{
"customPostId": 123,
"targetLanguageCode": "es"
}