쿼리 라이브러리
쿼리 라이브러리Bricks 콘텐츠 번역

Bricks 콘텐츠 번역

이 쿼리는 Bricks 페이지의 heading, text, text-basic, button, dropdown 요소의 콘텐츠를 다른 언어로 번역합니다.

이 쿼리를 사용하려면 Bricks 확장 기능Translation 확장 기능이 활성화되어 있어야 합니다.

이 쿼리에는 다음 변수가 필요합니다:

  • $customPostId: 업데이트할 Bricks 커스텀 포스트의 ID
  • $targetLanguageCode: 콘텐츠를 번역할 대상 언어 코드 (예: "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
      }
    }
  }
}