MenuQueries LibraryTranslate a post from the WordPress editor (Gutenberg)Translate a post from the WordPress editor (Gutenberg)This query translates a post to the desired language, with full support for Gutenberg, for the following block types: core/heading core/paragraph core/image core/button core/table core/list-item core/cover core/media-text core/verse core/quote core/pullquote core/audio core/video core/preformatted core/embed Depending on the $update parameter, the translation will either be saved under the same post, or as a new post. ######################################################################## # # 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 post to the desired language, # with full support for Gutenberg, for the following block types: # # - core/heading # - core/paragraph # - core/image # - core/button # - core/table # - core/list-item # - core/cover # - core/media-text # - core/verse # - core/quote # - core/pullquote # - core/audio # - core/video # - core/preformatted # - core/embed # # 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 # # ********************************************************************* # # More info: # - https://gatographql.com/tutorial/translating-block-content-in-a-post-to-a-different-language/ # ######################################################################## query InitializeVariables { isGutenbergEditorEnabled @export(as: "isGutenbergEditorEnabled") emptyArray: _echo(value: []) @export(as: "coreHeadingContentItems") @export(as: "coreHeadingContentReplacementsFrom") @export(as: "coreHeadingContentReplacementsTo") @export(as: "coreParagraphContentItems") @export(as: "coreParagraphContentReplacementsFrom") @export(as: "coreParagraphContentReplacementsTo") @export(as: "coreImageAltItems") @export(as: "coreImageAltReplacementsFrom") @export(as: "coreImageAltReplacementsTo") @export(as: "coreImageCaptionItems") @export(as: "coreImageCaptionReplacementsFrom") @export(as: "coreImageCaptionReplacementsTo") @export(as: "coreButtonTextItems") @export(as: "coreButtonTextReplacementsFrom") @export(as: "coreButtonTextReplacementsTo") @export(as: "coreTableCaptionItems") @export(as: "coreTableCaptionReplacementsFrom") @export(as: "coreTableCaptionReplacementsTo") @export(as: "coreTableBodyCellsContentItems") @export(as: "coreTableBodyCellsContentReplacementsFrom") @export(as: "coreTableBodyCellsContentReplacementsTo") @export(as: "coreListItemContentItems") @export(as: "coreListItemContentReplacementsFrom") @export(as: "coreListItemContentReplacementsTo") @export(as: "coreCoverAltItems") @export(as: "coreCoverAltReplacementsFrom") @export(as: "coreCoverAltReplacementsTo") @export(as: "coreMediaTextAltItems") @export(as: "coreMediaTextAltReplacementsFrom") @export(as: "coreMediaTextAltReplacementsTo") @export(as: "coreVerseContentItems") @export(as: "coreVerseContentReplacementsFrom") @export(as: "coreVerseContentReplacementsTo") @export(as: "coreQuoteCitationItems") @export(as: "coreQuoteCitationReplacementsFrom") @export(as: "coreQuoteCitationReplacementsTo") @export(as: "corePullquoteCitationItems") @export(as: "corePullquoteCitationReplacementsFrom") @export(as: "corePullquoteCitationReplacementsTo") @export(as: "corePullquoteValueItems") @export(as: "corePullquoteValueReplacementsFrom") @export(as: "corePullquoteValueReplacementsTo") @export(as: "coreAudioCaptionItems") @export(as: "coreAudioCaptionReplacementsFrom") @export(as: "coreAudioCaptionReplacementsTo") @export(as: "coreVideoCaptionItems") @export(as: "coreVideoCaptionReplacementsFrom") @export(as: "coreVideoCaptionReplacementsTo") @export(as: "corePreformattedContentItems") @export(as: "corePreformattedContentReplacementsFrom") @export(as: "corePreformattedContentReplacementsTo") @export(as: "coreEmbedCaptionItems") @export(as: "coreEmbedCaptionReplacementsFrom") @export(as: "coreEmbedCaptionReplacementsTo") @remove } query FetchData($postId: ID!) @configureWarningsOnExportingDuplicateVariable(enabled: false) @depends(on: "InitializeVariables") @include(if: $isGutenbergEditorEnabled) { post(by: { id: $postId }, status: any) { id title @export(as: "title") rawContent @export(as: "rawContent") coreHeading: blockFlattenedDataItems( filterBy: { include: "core/heading" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreHeadingContentItems" ) coreParagraph: blockFlattenedDataItems( filterBy: { include: "core/paragraph" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreParagraphContentItems" ) coreImage: blockFlattenedDataItems( filterBy: { include: "core/image" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "attributes" } affectDirectivesUnderPos: [1, 3] ) @underJSONObjectProperty( by: { key: "alt" } failIfNonExistingKeyOrPath: false ) @export( as: "coreImageAltItems" ) @underJSONObjectProperty( by: { key: "caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreImageCaptionItems" ) coreButton: blockFlattenedDataItems( filterBy: { include: "core/button" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.text" } failIfNonExistingKeyOrPath: false ) @export( as: "coreButtonTextItems" ) coreTable: blockFlattenedDataItems( filterBy: { include: "core/table" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "attributes" } affectDirectivesUnderPos: [1, 3] ) @underJSONObjectProperty( by: { key: "caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreTableCaptionItems" ) @underJSONObjectProperty( by: { key: "body" } failIfNonExistingKeyOrPath: false ) @underEachArrayItem @underJSONObjectProperty( by: { key: "cells" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "content" } ) @export( as: "coreTableBodyCellsContentItems" ) coreListItem: blockFlattenedDataItems( filterBy: { include: "core/list-item" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreListItemContentItems" ) coreCover: blockFlattenedDataItems( filterBy: { include: "core/cover" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.alt" } failIfNonExistingKeyOrPath: false ) @export( as: "coreCoverAltItems" ) coreMediaText: blockFlattenedDataItems( filterBy: { include: "core/media-text" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.mediaAlt" } failIfNonExistingKeyOrPath: false ) @export( as: "coreMediaTextAltItems" ) coreVerse: blockFlattenedDataItems( filterBy: { include: "core/verse" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreVerseContentItems" ) coreQuote: blockFlattenedDataItems( filterBy: { include: "core/quote" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.citation" } failIfNonExistingKeyOrPath: false ) @export( as: "coreQuoteCitationItems" ) corePullquote: blockFlattenedDataItems( filterBy: { include: "core/pullquote" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "attributes" } affectDirectivesUnderPos: [1, 3] ) @underJSONObjectProperty( by: { key: "citation" } failIfNonExistingKeyOrPath: false ) @export( as: "corePullquoteCitationItems" ) @underJSONObjectProperty( by: { key: "value" } failIfNonExistingKeyOrPath: false ) @export( as: "corePullquoteValueItems" ) coreAudio: blockFlattenedDataItems( filterBy: { include: "core/audio" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreAudioCaptionItems" ) coreVideo: blockFlattenedDataItems( filterBy: { include: "core/video" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreVideoCaptionItems" ) corePreformatted: blockFlattenedDataItems( filterBy: { include: "core/preformatted" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "corePreformattedContentItems" ) coreEmbed: blockFlattenedDataItems( filterBy: { include: "core/embed" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreEmbedCaptionItems" ) } } query TransformData( $toLang: String! ) @depends(on: "FetchData") @include(if: $isGutenbergEditorEnabled) { transformations: _echo(value: { meta: { from: [""], to: [$title], } coreHeadingContent: { from: $coreHeadingContentItems, to: $coreHeadingContentItems, }, coreParagraphContent: { from: $coreParagraphContentItems, to: $coreParagraphContentItems, }, coreImageAlt: { from: $coreImageAltItems, to: $coreImageAltItems, }, coreImageCaption: { from: $coreImageCaptionItems, to: $coreImageCaptionItems, }, coreButtonText: { from: $coreButtonTextItems to: $coreButtonTextItems }, coreTableCaption: { from: $coreTableCaptionItems, to: $coreTableCaptionItems, }, coreTableBodyCellsContent: { from: $coreTableBodyCellsContentItems, to: $coreTableBodyCellsContentItems, }, coreListItemContent: { from: $coreListItemContentItems, to: $coreListItemContentItems, }, coreCoverAlt: { from: $coreCoverAltItems, to: $coreCoverAltItems, }, coreMediaTextAlt: { from: $coreMediaTextAltItems, to: $coreMediaTextAltItems, }, coreVerseContent: { from: $coreVerseContentItems, to: $coreVerseContentItems, }, coreQuoteCitation: { from: $coreQuoteCitationItems, to: $coreQuoteCitationItems, }, corePullquoteCitation: { from: $corePullquoteCitationItems, to: $corePullquoteCitationItems, }, corePullquoteValue: { from: $corePullquoteValueItems, to: $corePullquoteValueItems, }, coreAudioCaption: { from: $coreAudioCaptionItems, to: $coreAudioCaptionItems, }, coreVideoCaption: { from: $coreVideoCaptionItems, to: $coreVideoCaptionItems, }, corePreformattedContent: { from: $corePreformattedContentItems, to: $corePreformattedContentItems, }, coreEmbedCaption: { from: $coreEmbedCaptionItems, to: $coreEmbedCaptionItems, }, }) @underEachJSONObjectProperty @underJSONObjectProperty(by: { key: "to" }) @underEachArrayItem @strTranslate(to: $toLang) @export(as: "transformations") } query EscapeRegexStrings @depends(on: "TransformData") @include(if: $isGutenbergEditorEnabled) { escapedRegexStrings: _echo(value: $transformations) @underEachJSONObjectProperty @underJSONObjectProperty(by: { key: "from" }) @underEachArrayItem @strQuoteRegex @underEachJSONObjectProperty( filter: { by: { excludeKeys: "meta" } } ) @underJSONObjectProperty( by: { key: "to" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem @strRegexReplace( searchRegex: "#\\$(\\d+)#", replaceWith: "\\\\\\$1" ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "${1}%s${2}", values: [$value] }, setResultInResponse: true ) @export(as: "escapedRegexTransformations") } query CreateRegexReplacements @depends(on: "EscapeRegexStrings") @include(if: $isGutenbergEditorEnabled) { regexReplacements: _echo(value: $escapedRegexTransformations) @underJSONObjectProperty( by: { key: "coreHeadingContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:heading .*?-->\\n?<h[1-6] ?.*?>)%s(</h[1-6]>\\n?<!-- /wp:heading -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreHeadingContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreHeadingContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreParagraphContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:paragraph .*?-->\\n?<p ?.*?>)%s(</p>\\n?<!-- /wp:paragraph -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreParagraphContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreParagraphContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreImageAlt" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:image .*?-->\\n?.*<img .*?alt=\\\")%s(\\\".*>.*\\n?<!-- /wp:image -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreImageAltReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreImageAltReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreImageCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:image .*?-->\\n?.*<figcaption ?.*?>)%s(</figcaption>.*\\n?<!-- /wp:image -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreImageCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreImageCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreButtonText" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:button .*?-->\\n?.*<a ?.*?>)%s(</a>.*\\n?<!-- /wp:button -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreButtonTextReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreButtonTextReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreTableCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:table .*?-->\\n?.*<figcaption ?.*?>.*)%s(.*</figcaption>.*\\n?<!-- /wp:table -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreTableCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreTableCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreTableBodyCellsContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:table .*?-->\\n?.*<table ?.*?>.*)%s(.*</table>.*\\n?<!-- /wp:table -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreTableBodyCellsContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreTableBodyCellsContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreListItemContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:list-item .*?-->\\n?<li ?.*?>)%s(</li>\\n?<!-- /wp:list-item -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreListItemContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreListItemContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreCoverAlt" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:cover .*?-->\\n?.*<img .*?alt=\\\")%s(\\\".*>.*\\n?<!-- /wp:cover -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreCoverAltReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreCoverAltReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreMediaTextAlt" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:media-text .*?-->\\n?<div .*><figure .*><img .*?alt=\\\")%s(\\\")#", values: [$value] }, setResultInResponse: true ) @export( as: "coreMediaTextAltReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreMediaTextAltReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreVerseContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:verse .*?-->\\n?<pre ?.*?>)%s(</pre>\\n?<!-- /wp:verse -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreVerseContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreVerseContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreQuoteCitation" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:quote .*?-->\\n?<blockquote ?.*?>.*<cite ?.*?>)%s(</cite></blockquote>\\n?<!-- /wp:quote -->)#s", values: [$value] }, setResultInResponse: true ) @export( as: "coreQuoteCitationReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreQuoteCitationReplacementsTo", ) @underJSONObjectProperty( by: { key: "corePullquoteCitation" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:pullquote .*?-->\\n?<figure ?.*?><blockquote ?.*?><p ?.*?>.*</p><cite ?.*?>)%s(</cite></blockquote></figure>\\n?<!-- /wp:pullquote -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "corePullquoteCitationReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "corePullquoteCitationReplacementsTo", ) @underJSONObjectProperty( by: { key: "corePullquoteValue" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:pullquote .*?-->\\n?<figure ?.*?><blockquote ?.*?><p ?.*?>)%s(</p>(?:<cite ?.*?>.*</cite>)?</blockquote></figure>\\n?<!-- /wp:pullquote -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "corePullquoteValueReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "corePullquoteValueReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreAudioCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:audio .*?-->\\n?<figure ?.*?><audio ?.*?>.*</audio><figcaption ?.*?>)%s(</figcaption></figure>\\n?<!-- /wp:audio -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreAudioCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreAudioCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreVideoCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:video .*?-->\\n?<figure ?.*?><video ?.*?>.*</video><figcaption ?.*?>)%s(</figcaption></figure>\\n?<!-- /wp:video -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreVideoCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreVideoCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "corePreformattedContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:preformatted .*?-->\\n?<pre ?.*?>)%s(</pre>\\n?<!-- /wp:preformatted -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "corePreformattedContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "corePreformattedContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreEmbedCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:embed .*?-->\\n?<figure ?.*?><div ?.*?>.*</div><figcaption ?.*?>)%s(</figcaption></figure>\\n?<!-- /wp:embed -->)#s", values: [$value] }, setResultInResponse: true ) @export( as: "coreEmbedCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreEmbedCaptionReplacementsTo", ) } query ExecuteRegexReplacements @depends(on: "CreateRegexReplacements") @include(if: $isGutenbergEditorEnabled) { transformedRawContent: _echo(value: $rawContent) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreHeadingContentReplacementsFrom, replaceWith: $coreHeadingContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreParagraphContentReplacementsFrom, replaceWith: $coreParagraphContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreImageAltReplacementsFrom, replaceWith: $coreImageAltReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreImageCaptionReplacementsFrom, replaceWith: $coreImageCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreButtonTextReplacementsFrom, replaceWith: $coreButtonTextReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreTableCaptionReplacementsFrom, replaceWith: $coreTableCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreTableBodyCellsContentReplacementsFrom, replaceWith: $coreTableBodyCellsContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreListItemContentReplacementsFrom, replaceWith: $coreListItemContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreCoverAltReplacementsFrom, replaceWith: $coreCoverAltReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreMediaTextAltReplacementsFrom, replaceWith: $coreMediaTextAltReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreVerseContentReplacementsFrom, replaceWith: $coreVerseContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreQuoteCitationReplacementsFrom, replaceWith: $coreQuoteCitationReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $corePullquoteCitationReplacementsFrom, replaceWith: $corePullquoteCitationReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $corePullquoteValueReplacementsFrom, replaceWith: $corePullquoteValueReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreAudioCaptionReplacementsFrom, replaceWith: $coreAudioCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreVideoCaptionReplacementsFrom, replaceWith: $coreVideoCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $corePreformattedContentReplacementsFrom, replaceWith: $corePreformattedContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreEmbedCaptionReplacementsFrom, replaceWith: $coreEmbedCaptionReplacementsTo ) @export(as: "transformedRawContent") } query PrepareMetaReplacements @depends(on: "TransformData") @include(if: $isGutenbergEditorEnabled) { transformedMeta: _objectProperty( object: $transformations, by: { path: "meta.to" } ) @underArrayItem(index: 0) @export(as: "transformedTitle") } mutation TranslateGutenbergPost( $postId: ID! $update: Boolean! = false ) @depends(on: [ "ExecuteRegexReplacements", "PrepareMetaReplacements" ] @include(if: $isGutenbergEditorEnabled) ) { createPost(input: { title: $transformedTitle, contentAs: { html: $transformedRawContent }, status: draft }) @skip(if: $update) { status errors { __typename ...on ErrorPayload { message } } post { id title slug rawContent } } updatePost(input: { id: $postId, title: $transformedTitle, contentAs: { html: $transformedRawContent } }) @include(if: $update) { status errors { __typename ...on ErrorPayload { message } } post { id title rawContent } } }CopyPrevTranslate a post from the "Classic editor"NextTranslate all properties of a post using ChatGPT
This query translates a post to the desired language, with full support for Gutenberg, for the following block types: core/heading core/paragraph core/image core/button core/table core/list-item core/cover core/media-text core/verse core/quote core/pullquote core/audio core/video core/preformatted core/embed Depending on the $update parameter, the translation will either be saved under the same post, or as a new post. ######################################################################## # # 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 post to the desired language, # with full support for Gutenberg, for the following block types: # # - core/heading # - core/paragraph # - core/image # - core/button # - core/table # - core/list-item # - core/cover # - core/media-text # - core/verse # - core/quote # - core/pullquote # - core/audio # - core/video # - core/preformatted # - core/embed # # 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 # # ********************************************************************* # # More info: # - https://gatographql.com/tutorial/translating-block-content-in-a-post-to-a-different-language/ # ######################################################################## query InitializeVariables { isGutenbergEditorEnabled @export(as: "isGutenbergEditorEnabled") emptyArray: _echo(value: []) @export(as: "coreHeadingContentItems") @export(as: "coreHeadingContentReplacementsFrom") @export(as: "coreHeadingContentReplacementsTo") @export(as: "coreParagraphContentItems") @export(as: "coreParagraphContentReplacementsFrom") @export(as: "coreParagraphContentReplacementsTo") @export(as: "coreImageAltItems") @export(as: "coreImageAltReplacementsFrom") @export(as: "coreImageAltReplacementsTo") @export(as: "coreImageCaptionItems") @export(as: "coreImageCaptionReplacementsFrom") @export(as: "coreImageCaptionReplacementsTo") @export(as: "coreButtonTextItems") @export(as: "coreButtonTextReplacementsFrom") @export(as: "coreButtonTextReplacementsTo") @export(as: "coreTableCaptionItems") @export(as: "coreTableCaptionReplacementsFrom") @export(as: "coreTableCaptionReplacementsTo") @export(as: "coreTableBodyCellsContentItems") @export(as: "coreTableBodyCellsContentReplacementsFrom") @export(as: "coreTableBodyCellsContentReplacementsTo") @export(as: "coreListItemContentItems") @export(as: "coreListItemContentReplacementsFrom") @export(as: "coreListItemContentReplacementsTo") @export(as: "coreCoverAltItems") @export(as: "coreCoverAltReplacementsFrom") @export(as: "coreCoverAltReplacementsTo") @export(as: "coreMediaTextAltItems") @export(as: "coreMediaTextAltReplacementsFrom") @export(as: "coreMediaTextAltReplacementsTo") @export(as: "coreVerseContentItems") @export(as: "coreVerseContentReplacementsFrom") @export(as: "coreVerseContentReplacementsTo") @export(as: "coreQuoteCitationItems") @export(as: "coreQuoteCitationReplacementsFrom") @export(as: "coreQuoteCitationReplacementsTo") @export(as: "corePullquoteCitationItems") @export(as: "corePullquoteCitationReplacementsFrom") @export(as: "corePullquoteCitationReplacementsTo") @export(as: "corePullquoteValueItems") @export(as: "corePullquoteValueReplacementsFrom") @export(as: "corePullquoteValueReplacementsTo") @export(as: "coreAudioCaptionItems") @export(as: "coreAudioCaptionReplacementsFrom") @export(as: "coreAudioCaptionReplacementsTo") @export(as: "coreVideoCaptionItems") @export(as: "coreVideoCaptionReplacementsFrom") @export(as: "coreVideoCaptionReplacementsTo") @export(as: "corePreformattedContentItems") @export(as: "corePreformattedContentReplacementsFrom") @export(as: "corePreformattedContentReplacementsTo") @export(as: "coreEmbedCaptionItems") @export(as: "coreEmbedCaptionReplacementsFrom") @export(as: "coreEmbedCaptionReplacementsTo") @remove } query FetchData($postId: ID!) @configureWarningsOnExportingDuplicateVariable(enabled: false) @depends(on: "InitializeVariables") @include(if: $isGutenbergEditorEnabled) { post(by: { id: $postId }, status: any) { id title @export(as: "title") rawContent @export(as: "rawContent") coreHeading: blockFlattenedDataItems( filterBy: { include: "core/heading" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreHeadingContentItems" ) coreParagraph: blockFlattenedDataItems( filterBy: { include: "core/paragraph" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreParagraphContentItems" ) coreImage: blockFlattenedDataItems( filterBy: { include: "core/image" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "attributes" } affectDirectivesUnderPos: [1, 3] ) @underJSONObjectProperty( by: { key: "alt" } failIfNonExistingKeyOrPath: false ) @export( as: "coreImageAltItems" ) @underJSONObjectProperty( by: { key: "caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreImageCaptionItems" ) coreButton: blockFlattenedDataItems( filterBy: { include: "core/button" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.text" } failIfNonExistingKeyOrPath: false ) @export( as: "coreButtonTextItems" ) coreTable: blockFlattenedDataItems( filterBy: { include: "core/table" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "attributes" } affectDirectivesUnderPos: [1, 3] ) @underJSONObjectProperty( by: { key: "caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreTableCaptionItems" ) @underJSONObjectProperty( by: { key: "body" } failIfNonExistingKeyOrPath: false ) @underEachArrayItem @underJSONObjectProperty( by: { key: "cells" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "content" } ) @export( as: "coreTableBodyCellsContentItems" ) coreListItem: blockFlattenedDataItems( filterBy: { include: "core/list-item" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreListItemContentItems" ) coreCover: blockFlattenedDataItems( filterBy: { include: "core/cover" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.alt" } failIfNonExistingKeyOrPath: false ) @export( as: "coreCoverAltItems" ) coreMediaText: blockFlattenedDataItems( filterBy: { include: "core/media-text" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.mediaAlt" } failIfNonExistingKeyOrPath: false ) @export( as: "coreMediaTextAltItems" ) coreVerse: blockFlattenedDataItems( filterBy: { include: "core/verse" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "coreVerseContentItems" ) coreQuote: blockFlattenedDataItems( filterBy: { include: "core/quote" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.citation" } failIfNonExistingKeyOrPath: false ) @export( as: "coreQuoteCitationItems" ) corePullquote: blockFlattenedDataItems( filterBy: { include: "core/pullquote" } ) @underEachArrayItem @underJSONObjectProperty( by: { key: "attributes" } affectDirectivesUnderPos: [1, 3] ) @underJSONObjectProperty( by: { key: "citation" } failIfNonExistingKeyOrPath: false ) @export( as: "corePullquoteCitationItems" ) @underJSONObjectProperty( by: { key: "value" } failIfNonExistingKeyOrPath: false ) @export( as: "corePullquoteValueItems" ) coreAudio: blockFlattenedDataItems( filterBy: { include: "core/audio" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreAudioCaptionItems" ) coreVideo: blockFlattenedDataItems( filterBy: { include: "core/video" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreVideoCaptionItems" ) corePreformatted: blockFlattenedDataItems( filterBy: { include: "core/preformatted" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.content" } failIfNonExistingKeyOrPath: false ) @export( as: "corePreformattedContentItems" ) coreEmbed: blockFlattenedDataItems( filterBy: { include: "core/embed" } ) @underEachArrayItem @underJSONObjectProperty( by: { path: "attributes.caption" } failIfNonExistingKeyOrPath: false ) @export( as: "coreEmbedCaptionItems" ) } } query TransformData( $toLang: String! ) @depends(on: "FetchData") @include(if: $isGutenbergEditorEnabled) { transformations: _echo(value: { meta: { from: [""], to: [$title], } coreHeadingContent: { from: $coreHeadingContentItems, to: $coreHeadingContentItems, }, coreParagraphContent: { from: $coreParagraphContentItems, to: $coreParagraphContentItems, }, coreImageAlt: { from: $coreImageAltItems, to: $coreImageAltItems, }, coreImageCaption: { from: $coreImageCaptionItems, to: $coreImageCaptionItems, }, coreButtonText: { from: $coreButtonTextItems to: $coreButtonTextItems }, coreTableCaption: { from: $coreTableCaptionItems, to: $coreTableCaptionItems, }, coreTableBodyCellsContent: { from: $coreTableBodyCellsContentItems, to: $coreTableBodyCellsContentItems, }, coreListItemContent: { from: $coreListItemContentItems, to: $coreListItemContentItems, }, coreCoverAlt: { from: $coreCoverAltItems, to: $coreCoverAltItems, }, coreMediaTextAlt: { from: $coreMediaTextAltItems, to: $coreMediaTextAltItems, }, coreVerseContent: { from: $coreVerseContentItems, to: $coreVerseContentItems, }, coreQuoteCitation: { from: $coreQuoteCitationItems, to: $coreQuoteCitationItems, }, corePullquoteCitation: { from: $corePullquoteCitationItems, to: $corePullquoteCitationItems, }, corePullquoteValue: { from: $corePullquoteValueItems, to: $corePullquoteValueItems, }, coreAudioCaption: { from: $coreAudioCaptionItems, to: $coreAudioCaptionItems, }, coreVideoCaption: { from: $coreVideoCaptionItems, to: $coreVideoCaptionItems, }, corePreformattedContent: { from: $corePreformattedContentItems, to: $corePreformattedContentItems, }, coreEmbedCaption: { from: $coreEmbedCaptionItems, to: $coreEmbedCaptionItems, }, }) @underEachJSONObjectProperty @underJSONObjectProperty(by: { key: "to" }) @underEachArrayItem @strTranslate(to: $toLang) @export(as: "transformations") } query EscapeRegexStrings @depends(on: "TransformData") @include(if: $isGutenbergEditorEnabled) { escapedRegexStrings: _echo(value: $transformations) @underEachJSONObjectProperty @underJSONObjectProperty(by: { key: "from" }) @underEachArrayItem @strQuoteRegex @underEachJSONObjectProperty( filter: { by: { excludeKeys: "meta" } } ) @underJSONObjectProperty( by: { key: "to" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem @strRegexReplace( searchRegex: "#\\$(\\d+)#", replaceWith: "\\\\\\$1" ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "${1}%s${2}", values: [$value] }, setResultInResponse: true ) @export(as: "escapedRegexTransformations") } query CreateRegexReplacements @depends(on: "EscapeRegexStrings") @include(if: $isGutenbergEditorEnabled) { regexReplacements: _echo(value: $escapedRegexTransformations) @underJSONObjectProperty( by: { key: "coreHeadingContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:heading .*?-->\\n?<h[1-6] ?.*?>)%s(</h[1-6]>\\n?<!-- /wp:heading -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreHeadingContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreHeadingContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreParagraphContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:paragraph .*?-->\\n?<p ?.*?>)%s(</p>\\n?<!-- /wp:paragraph -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreParagraphContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreParagraphContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreImageAlt" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:image .*?-->\\n?.*<img .*?alt=\\\")%s(\\\".*>.*\\n?<!-- /wp:image -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreImageAltReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreImageAltReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreImageCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:image .*?-->\\n?.*<figcaption ?.*?>)%s(</figcaption>.*\\n?<!-- /wp:image -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreImageCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreImageCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreButtonText" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:button .*?-->\\n?.*<a ?.*?>)%s(</a>.*\\n?<!-- /wp:button -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreButtonTextReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreButtonTextReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreTableCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:table .*?-->\\n?.*<figcaption ?.*?>.*)%s(.*</figcaption>.*\\n?<!-- /wp:table -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreTableCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreTableCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreTableBodyCellsContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:table .*?-->\\n?.*<table ?.*?>.*)%s(.*</table>.*\\n?<!-- /wp:table -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreTableBodyCellsContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreTableBodyCellsContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreListItemContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:list-item .*?-->\\n?<li ?.*?>)%s(</li>\\n?<!-- /wp:list-item -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreListItemContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreListItemContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreCoverAlt" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:cover .*?-->\\n?.*<img .*?alt=\\\")%s(\\\".*>.*\\n?<!-- /wp:cover -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreCoverAltReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreCoverAltReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreMediaTextAlt" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:media-text .*?-->\\n?<div .*><figure .*><img .*?alt=\\\")%s(\\\")#", values: [$value] }, setResultInResponse: true ) @export( as: "coreMediaTextAltReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreMediaTextAltReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreVerseContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:verse .*?-->\\n?<pre ?.*?>)%s(</pre>\\n?<!-- /wp:verse -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreVerseContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreVerseContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreQuoteCitation" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:quote .*?-->\\n?<blockquote ?.*?>.*<cite ?.*?>)%s(</cite></blockquote>\\n?<!-- /wp:quote -->)#s", values: [$value] }, setResultInResponse: true ) @export( as: "coreQuoteCitationReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreQuoteCitationReplacementsTo", ) @underJSONObjectProperty( by: { key: "corePullquoteCitation" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:pullquote .*?-->\\n?<figure ?.*?><blockquote ?.*?><p ?.*?>.*</p><cite ?.*?>)%s(</cite></blockquote></figure>\\n?<!-- /wp:pullquote -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "corePullquoteCitationReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "corePullquoteCitationReplacementsTo", ) @underJSONObjectProperty( by: { key: "corePullquoteValue" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:pullquote .*?-->\\n?<figure ?.*?><blockquote ?.*?><p ?.*?>)%s(</p>(?:<cite ?.*?>.*</cite>)?</blockquote></figure>\\n?<!-- /wp:pullquote -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "corePullquoteValueReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "corePullquoteValueReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreAudioCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:audio .*?-->\\n?<figure ?.*?><audio ?.*?>.*</audio><figcaption ?.*?>)%s(</figcaption></figure>\\n?<!-- /wp:audio -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreAudioCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreAudioCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreVideoCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:video .*?-->\\n?<figure ?.*?><video ?.*?>.*</video><figcaption ?.*?>)%s(</figcaption></figure>\\n?<!-- /wp:video -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "coreVideoCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreVideoCaptionReplacementsTo", ) @underJSONObjectProperty( by: { key: "corePreformattedContent" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:preformatted .*?-->\\n?<pre ?.*?>)%s(</pre>\\n?<!-- /wp:preformatted -->)#", values: [$value] }, setResultInResponse: true ) @export( as: "corePreformattedContentReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "corePreformattedContentReplacementsTo", ) @underJSONObjectProperty( by: { key: "coreEmbedCaption" } affectDirectivesUnderPos: [1, 5] ) @underJSONObjectProperty( by: { key: "from" } affectDirectivesUnderPos: [1, 3], ) @underEachArrayItem( passValueOnwardsAs: "value" ) @applyField( name: "_sprintf", arguments: { string: "#(<!-- wp:embed .*?-->\\n?<figure ?.*?><div ?.*?>.*</div><figcaption ?.*?>)%s(</figcaption></figure>\\n?<!-- /wp:embed -->)#s", values: [$value] }, setResultInResponse: true ) @export( as: "coreEmbedCaptionReplacementsFrom", ) @underJSONObjectProperty( by: { key: "to" } ) @export( as: "coreEmbedCaptionReplacementsTo", ) } query ExecuteRegexReplacements @depends(on: "CreateRegexReplacements") @include(if: $isGutenbergEditorEnabled) { transformedRawContent: _echo(value: $rawContent) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreHeadingContentReplacementsFrom, replaceWith: $coreHeadingContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreParagraphContentReplacementsFrom, replaceWith: $coreParagraphContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreImageAltReplacementsFrom, replaceWith: $coreImageAltReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreImageCaptionReplacementsFrom, replaceWith: $coreImageCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreButtonTextReplacementsFrom, replaceWith: $coreButtonTextReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreTableCaptionReplacementsFrom, replaceWith: $coreTableCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreTableBodyCellsContentReplacementsFrom, replaceWith: $coreTableBodyCellsContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreListItemContentReplacementsFrom, replaceWith: $coreListItemContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreCoverAltReplacementsFrom, replaceWith: $coreCoverAltReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreMediaTextAltReplacementsFrom, replaceWith: $coreMediaTextAltReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreVerseContentReplacementsFrom, replaceWith: $coreVerseContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreQuoteCitationReplacementsFrom, replaceWith: $coreQuoteCitationReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $corePullquoteCitationReplacementsFrom, replaceWith: $corePullquoteCitationReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $corePullquoteValueReplacementsFrom, replaceWith: $corePullquoteValueReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreAudioCaptionReplacementsFrom, replaceWith: $coreAudioCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreVideoCaptionReplacementsFrom, replaceWith: $coreVideoCaptionReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $corePreformattedContentReplacementsFrom, replaceWith: $corePreformattedContentReplacementsTo ) @strRegexReplaceMultiple( limit: 1, searchRegex: $coreEmbedCaptionReplacementsFrom, replaceWith: $coreEmbedCaptionReplacementsTo ) @export(as: "transformedRawContent") } query PrepareMetaReplacements @depends(on: "TransformData") @include(if: $isGutenbergEditorEnabled) { transformedMeta: _objectProperty( object: $transformations, by: { path: "meta.to" } ) @underArrayItem(index: 0) @export(as: "transformedTitle") } mutation TranslateGutenbergPost( $postId: ID! $update: Boolean! = false ) @depends(on: [ "ExecuteRegexReplacements", "PrepareMetaReplacements" ] @include(if: $isGutenbergEditorEnabled) ) { createPost(input: { title: $transformedTitle, contentAs: { html: $transformedRawContent }, status: draft }) @skip(if: $update) { status errors { __typename ...on ErrorPayload { message } } post { id title slug rawContent } } updatePost(input: { id: $postId, title: $transformedTitle, contentAs: { html: $transformedRawContent } }) @include(if: $update) { status errors { __typename ...on ErrorPayload { message } } post { id title rawContent } } }Copy