diff --git a/build/blocks/block-coauthors/block.json b/build/blocks/block-coauthors/block.json index 08bc0a92..ea25755b 100644 --- a/build/blocks/block-coauthors/block.json +++ b/build/blocks/block-coauthors/block.json @@ -40,28 +40,12 @@ } }, "attributes": { - "separator": { - "type": "string", - "default": ", " - }, - "lastSeparator": { - "type": "string", - "default": " and " - }, "layout": { "type": "object", "default": { "type": "inline" } }, - "prefix": { - "type": "string", - "default": "By " - }, - "suffix": { - "type": "string", - "default": "" - }, "textAlign": { "type": "string" } diff --git a/php/blocks/block-coauthors/class-block-coauthors.php b/php/blocks/block-coauthors/class-block-coauthors.php index 9add8e35..794e2206 100644 --- a/php/blocks/block-coauthors/class-block-coauthors.php +++ b/php/blocks/block-coauthors/class-block-coauthors.php @@ -22,6 +22,9 @@ class Block_CoAuthors { * @since 3.6.0 */ public static function register_block(): void { + + add_filter( 'block_type_metadata_settings', array( __CLASS__, 'separator_internationalization' ), 10, 2 ); + register_block_type( dirname( COAUTHORS_PLUS_FILE ) . '/build/blocks/block-coauthors', array( @@ -30,6 +33,52 @@ public static function register_block(): void { ); } + /** + * Separator Internationalization + * Provide i18n for the default prefix, separators and suffix attributes during block registration. + * + * @param array $settings Array of determined settings for registering a block type. + * @param array $metadata Metadata provided for registering a block type. + * @return array Updated settings that include internationalized attributes. + */ + public static function separator_internationalization( array $settings, array $metadata ): array { + + if ( ! array_key_exists( 'name', $metadata ) ) { + return $settings; + } + + if ( 'cap/coauthors' !== $metadata['name'] ) { + return $settings; + } + + return array_merge( + $settings, + array( + 'attributes' => array_merge( + $settings['attributes'], + array( + 'prefix' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_before', __( 'By ', 'co-authors-plus' ) ), + ), + 'separator' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_between', ', ' ), + ), + 'lastSeparator' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_between_last', __( ' and ', 'co-authors-plus' ) ), + ), + 'suffix' => array( + 'type' => 'string', + 'default' => apply_filters( 'coauthors_default_after', '' ), + ), + ) + ), + ) + ); + } + /** * Render Block * diff --git a/src/blocks/block-coauthors/block.json b/src/blocks/block-coauthors/block.json index 72aa1aab..28ba4d55 100644 --- a/src/blocks/block-coauthors/block.json +++ b/src/blocks/block-coauthors/block.json @@ -38,28 +38,12 @@ } }, "attributes": { - "separator": { - "type": "string", - "default": ", " - }, - "lastSeparator": { - "type": "string", - "default": " and " - }, "layout": { "type": "object", "default": { "type": "inline" } }, - "prefix": { - "type": "string", - "default": "By " - }, - "suffix": { - "type": "string", - "default": "" - }, "textAlign": { "type": "string" }