From b851c2f3e3e91e8d200ba1036e3d7c6f17539d3a Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 23 Apr 2021 09:34:26 +0200 Subject: [PATCH] Add i18n support for variations read from block metadata --- packages/blocks/src/api/i18n-block.json | 11 ++++-- packages/blocks/src/api/registration.js | 3 +- packages/blocks/src/api/test/registration.js | 40 ++++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/packages/blocks/src/api/i18n-block.json b/packages/blocks/src/api/i18n-block.json index 9b44a6ec078aea..3d31f78592eaaf 100644 --- a/packages/blocks/src/api/i18n-block.json +++ b/packages/blocks/src/api/i18n-block.json @@ -1,12 +1,17 @@ { "title": "block title", "description": "block description", - "keywords": [ - "block keyword" - ], + "keywords": [ "block keyword" ], "styles": [ { "label": "block style label" } + ], + "variations": [ + { + "title": "block variation title", + "description": "block variation description", + "keywords": [ "block variation keyword" ] + } ] } diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index 7a4e0f901e46f7..b1f62fe4ee9cb1 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -387,6 +387,7 @@ export function registerBlockTypeFromMetadata( additionalSettings ) { const allowedFields = [ + 'apiVersion', 'title', 'category', 'parent', @@ -399,7 +400,7 @@ export function registerBlockTypeFromMetadata( 'supports', 'styles', 'example', - 'apiVersion', + 'variations', ]; const settings = pick( metadata, allowedFields ); diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index ead44e97c1021e..b8d7c9c4137544 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -812,6 +812,14 @@ describe( 'blocks', () => { title: 'Block from metadata', category: 'text', icon: 'palmtree', + variations: [ + { + name: 'variation', + title: 'Variation Title', + description: 'Variation description', + keywords: [ 'variation' ], + }, + ], }, { edit: Edit, @@ -831,6 +839,14 @@ describe( 'blocks', () => { usesContext: [], supports: {}, styles: [], + variations: [ + { + name: 'variation', + title: 'Variation Title', + description: 'Variation description', + keywords: [ 'variation' ], + }, + ], edit: Edit, save: noop, } ); @@ -851,8 +867,16 @@ describe( 'blocks', () => { keywords: [ 'i18n', 'metadata' ], styles: [ { - name: 'i18n-metadata', - label: 'I18n Metadata', + name: 'i18n-style', + label: 'I18n Style Label', + }, + ], + variations: [ + { + name: 'i18n-variation', + title: 'I18n Variation Title', + description: 'I18n variation description', + keywords: [ 'variation' ], }, ], textdomain: 'test', @@ -882,8 +906,16 @@ describe( 'blocks', () => { supports: {}, styles: [ { - name: 'i18n-metadata', - label: 'I18n Metadata (translated)', + name: 'i18n-style', + label: 'I18n Style Label (translated)', + }, + ], + variations: [ + { + name: 'i18n-variation', + title: 'I18n Variation Title (translated)', + description: 'I18n variation description (translated)', + keywords: [ 'variation (translated)' ], }, ], edit: Edit,