From 46a7f7254e121b31ec526b294cd73abc6a5ae081 Mon Sep 17 00:00:00 2001 From: Kevin Zoschke Date: Tue, 19 Sep 2023 10:01:00 -0400 Subject: [PATCH 1/3] Fix blocks localization --- .../jetpack/changelog/fix-blocks-localization | 4 +++ .../extensions/blocks/ai-chat/editor.js | 2 -- .../blocks/business-hours/block.json | 6 ++-- .../shared/register-jetpack-block.js | 34 ++++++++++++++++--- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/fix-blocks-localization diff --git a/projects/plugins/jetpack/changelog/fix-blocks-localization b/projects/plugins/jetpack/changelog/fix-blocks-localization new file mode 100644 index 0000000000000..b3a784589d9a4 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-blocks-localization @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Fix blocks title and description not localized diff --git a/projects/plugins/jetpack/extensions/blocks/ai-chat/editor.js b/projects/plugins/jetpack/extensions/blocks/ai-chat/editor.js index 3b980e082b653..b4c8833bc2c77 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-chat/editor.js +++ b/projects/plugins/jetpack/extensions/blocks/ai-chat/editor.js @@ -7,8 +7,6 @@ import './editor.scss'; import './components/feedback/style.scss'; registerJetpackBlockFromMetadata( metadata, { - // The API version needs to be explicitly specified in this instance for styles to be loaded. - apiVersion: metadata.apiVersion, edit, save, } ); diff --git a/projects/plugins/jetpack/extensions/blocks/business-hours/block.json b/projects/plugins/jetpack/extensions/blocks/business-hours/block.json index 604d189d02881..f636fecebc223 100644 --- a/projects/plugins/jetpack/extensions/blocks/business-hours/block.json +++ b/projects/plugins/jetpack/extensions/blocks/business-hours/block.json @@ -1,10 +1,10 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, + "apiVersion": 1, "name": "jetpack/business-hours", "title": "Business Hours", "description": "Display opening hours for your business.", - "keywords": ["opening hours", "closing time", "schedule", "working day"], + "keywords": [ "opening hours", "closing time", "schedule", "working day" ], "version": "12.5.0", "textdomain": "jetpack", "category": "grow", @@ -22,7 +22,7 @@ "fontSize": true, "lineHeight": true }, - "align": ["wide", "full"] + "align": [ "wide", "full" ] }, "attributes": { "days": { diff --git a/projects/plugins/jetpack/extensions/shared/register-jetpack-block.js b/projects/plugins/jetpack/extensions/shared/register-jetpack-block.js index 481da6507feca..e426a51cb179a 100644 --- a/projects/plugins/jetpack/extensions/shared/register-jetpack-block.js +++ b/projects/plugins/jetpack/extensions/shared/register-jetpack-block.js @@ -6,8 +6,11 @@ import { } from '@automattic/jetpack-shared-extension-utils'; import { registerBlockType } from '@wordpress/blocks'; import { addFilter } from '@wordpress/hooks'; +import { _x } from '@wordpress/i18n'; const JETPACK_PREFIX = 'jetpack/'; +const LOCALIZED_BLOCK_PROPERTIES = [ 'title', 'description', 'keywords' ]; +const DEFAULT_TEXTDOMAIN = 'jetpack'; /** * Registers a gutenberg block if the availability requirements are met. @@ -59,6 +62,24 @@ export default function registerJetpackBlock( name, settings, childBlocks = [], return result; } +// Localize properties passed as parameter when applicable. +// Note: the documentation states that `registerBlockType` wraps localized properties in `_x` +// when it is passed the metadata object as the first param. I haven't found this to be true +// with the latest version of `@wordpress/blocks` (12.18.0) at the time of writing this. +// https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#javascript +const localizeBlockProperties = ( metadata, props ) => { + const result = { ...props }; + + for ( const prop in props ) { + if ( LOCALIZED_BLOCK_PROPERTIES.includes( prop ) ) { + // eslint-disable-next-line + result[ prop ] = _x( props[ prop ], null, metadata.textdomain || DEFAULT_TEXTDOMAIN ); + } + } + + return result; +}; + /** * Wrapper around registerJetpackBlock to register a block by specifying its metadata. * @@ -69,20 +90,25 @@ export default function registerJetpackBlock( name, settings, childBlocks = [], * @returns {object|boolean} Either false if the block is not available, or the results of `registerBlockType` */ export function registerJetpackBlockFromMetadata( metadata, settings, childBlocks, prefix ) { - const clientSettings = { + const mergedSettings = { + ...metadata, ...settings, + }; + const processedSettings = { + ...localizeBlockProperties( metadata, mergedSettings ), icon: getBlockIconProp( metadata ), }; + const { variations } = metadata; if ( Array.isArray( variations ) && variations.length > 0 ) { - clientSettings.variations = variations.map( variation => { + processedSettings.variations = variations.map( variation => { return { - ...variation, + ...localizeBlockProperties( metadata, variation ), icon: getBlockIconProp( variation ), }; } ); } - return registerJetpackBlock( metadata.name, clientSettings, childBlocks, prefix ); + return registerJetpackBlock( metadata.name, processedSettings, childBlocks, prefix ); } From 3e1364e5ea17e54f15ee15a2d1496123a1ac490a Mon Sep 17 00:00:00 2001 From: Kevin Zoschke Date: Tue, 19 Sep 2023 15:57:30 -0400 Subject: [PATCH 2/3] Fix versions mismatch --- projects/packages/jetpack-mu-wpcom/composer.json | 2 +- projects/packages/jetpack-mu-wpcom/package.json | 2 +- .../packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php | 2 +- projects/packages/sync/src/class-package-version.php | 2 +- .../mu-wpcom-plugin/changelog/fix-block-missing-translation | 5 +++++ projects/plugins/mu-wpcom-plugin/composer.json | 2 +- projects/plugins/mu-wpcom-plugin/composer.lock | 4 ++-- projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php | 2 +- projects/plugins/mu-wpcom-plugin/package.json | 2 +- 9 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 projects/plugins/mu-wpcom-plugin/changelog/fix-block-missing-translation diff --git a/projects/packages/jetpack-mu-wpcom/composer.json b/projects/packages/jetpack-mu-wpcom/composer.json index 0e72537e3842b..1c5859ddb79a3 100644 --- a/projects/packages/jetpack-mu-wpcom/composer.json +++ b/projects/packages/jetpack-mu-wpcom/composer.json @@ -47,7 +47,7 @@ }, "autotagger": true, "branch-alias": { - "dev-trunk": "4.10.x-dev" + "dev-trunk": "4.11.x-dev" }, "textdomain": "jetpack-mu-wpcom", "version-constants": { diff --git a/projects/packages/jetpack-mu-wpcom/package.json b/projects/packages/jetpack-mu-wpcom/package.json index 505c1a53f6cd1..0da0b47d9c775 100644 --- a/projects/packages/jetpack-mu-wpcom/package.json +++ b/projects/packages/jetpack-mu-wpcom/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-mu-wpcom", - "version": "4.10.0", + "version": "4.11.0-alpha", "description": "Enhances your site with features powered by WordPress.com", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme", "bugs": { diff --git a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php index 511b25ffb6acd..e3897ec3c8d13 100644 --- a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php +++ b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php @@ -14,7 +14,7 @@ */ class Jetpack_Mu_Wpcom { - const PACKAGE_VERSION = '4.10.0'; + const PACKAGE_VERSION = '4.11.0-alpha'; const PKG_DIR = __DIR__ . '/../'; /** diff --git a/projects/packages/sync/src/class-package-version.php b/projects/packages/sync/src/class-package-version.php index 311a6142ca3b2..774b422b3b888 100644 --- a/projects/packages/sync/src/class-package-version.php +++ b/projects/packages/sync/src/class-package-version.php @@ -12,7 +12,7 @@ */ class Package_Version { - const PACKAGE_VERSION = '1.57.0'; + const PACKAGE_VERSION = '1.57.1-alpha'; const PACKAGE_SLUG = 'sync'; diff --git a/projects/plugins/mu-wpcom-plugin/changelog/fix-block-missing-translation b/projects/plugins/mu-wpcom-plugin/changelog/fix-block-missing-translation new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/fix-block-missing-translation @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/mu-wpcom-plugin/composer.json b/projects/plugins/mu-wpcom-plugin/composer.json index d05924d5b1e0c..b4b30b283e8b1 100644 --- a/projects/plugins/mu-wpcom-plugin/composer.json +++ b/projects/plugins/mu-wpcom-plugin/composer.json @@ -46,6 +46,6 @@ ] }, "config": { - "autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ1_6_20" + "autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ1_6_21_alpha" } } diff --git a/projects/plugins/mu-wpcom-plugin/composer.lock b/projects/plugins/mu-wpcom-plugin/composer.lock index 964ca00e85b6d..232a1b95e37fa 100644 --- a/projects/plugins/mu-wpcom-plugin/composer.lock +++ b/projects/plugins/mu-wpcom-plugin/composer.lock @@ -12,7 +12,7 @@ "dist": { "type": "path", "url": "../../packages/jetpack-mu-wpcom", - "reference": "a97bf2e2d9e8d00007b082bce5ee69c3249504c6" + "reference": "42f702a13ab337ae035fcd24b9e915e779ac8647" }, "require-dev": { "automattic/jetpack-changelogger": "@dev", @@ -30,7 +30,7 @@ }, "autotagger": true, "branch-alias": { - "dev-trunk": "4.10.x-dev" + "dev-trunk": "4.11.x-dev" }, "textdomain": "jetpack-mu-wpcom", "version-constants": { diff --git a/projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php b/projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php index 6f05d88035aa2..ae8dbb98f1dfd 100644 --- a/projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php +++ b/projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php @@ -3,7 +3,7 @@ * * Plugin Name: WordPress.com Features * Description: Test plugin for the jetpack-mu-wpcom package - * Version: 1.6.20 + * Version: 1.6.21-alpha * Author: Automattic * License: GPLv2 or later * Text Domain: jetpack-mu-wpcom-plugin diff --git a/projects/plugins/mu-wpcom-plugin/package.json b/projects/plugins/mu-wpcom-plugin/package.json index f55485074f423..c27337ff838aa 100644 --- a/projects/plugins/mu-wpcom-plugin/package.json +++ b/projects/plugins/mu-wpcom-plugin/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-mu-wpcom-plugin", - "version": "1.6.20", + "version": "1.6.21-alpha", "description": "Test plugin for the jetpack-mu-wpcom package", "homepage": "https://jetpack.com", "bugs": { From 57c470f7a4ad3e87fb76d4f75df86d442c414ee2 Mon Sep 17 00:00:00 2001 From: Kevin Zoschke Date: Tue, 19 Sep 2023 15:57:57 -0400 Subject: [PATCH 3/3] changelog --- .../jetpack-mu-wpcom/changelog/fix-block-missing-translation | 4 ++++ .../packages/sync/changelog/fix-block-missing-translation | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/fix-block-missing-translation create mode 100644 projects/packages/sync/changelog/fix-block-missing-translation diff --git a/projects/packages/jetpack-mu-wpcom/changelog/fix-block-missing-translation b/projects/packages/jetpack-mu-wpcom/changelog/fix-block-missing-translation new file mode 100644 index 0000000000000..54ae413cd5cd7 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/fix-block-missing-translation @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix version mismatch diff --git a/projects/packages/sync/changelog/fix-block-missing-translation b/projects/packages/sync/changelog/fix-block-missing-translation new file mode 100644 index 0000000000000..54ae413cd5cd7 --- /dev/null +++ b/projects/packages/sync/changelog/fix-block-missing-translation @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix version mismatch