Skip to content

Commit

Permalink
Add i18n support for variations read from block metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 23, 2021
1 parent 18c991e commit b851c2f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
11 changes: 8 additions & 3 deletions packages/blocks/src/api/i18n-block.json
Original file line number Diff line number Diff line change
@@ -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" ]
}
]
}
3 changes: 2 additions & 1 deletion packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export function registerBlockTypeFromMetadata(
additionalSettings
) {
const allowedFields = [
'apiVersion',
'title',
'category',
'parent',
Expand All @@ -399,7 +400,7 @@ export function registerBlockTypeFromMetadata(
'supports',
'styles',
'example',
'apiVersion',
'variations',
];

const settings = pick( metadata, allowedFields );
Expand Down
40 changes: 36 additions & 4 deletions packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -831,6 +839,14 @@ describe( 'blocks', () => {
usesContext: [],
supports: {},
styles: [],
variations: [
{
name: 'variation',
title: 'Variation Title',
description: 'Variation description',
keywords: [ 'variation' ],
},
],
edit: Edit,
save: noop,
} );
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b851c2f

Please sign in to comment.