Skip to content

Use i18n schema for block.json from WordPress Core #287

@gziolo

Description

@gziolo

Feature Request

Describe your use case and the problem you are facing

BlockExtractor is using a hardcoded list of fields to translate from block.json file:

case 'title':
case 'description':
$translation = $translations->insert( sprintf( 'block %s', $key ), $original );
if ( $add_reference ) {
$translation->addReference( $file );
}
break;
case 'keywords':
if ( ! is_array( $original ) ) {
continue 2;
}
foreach ( $original as $msg ) {
$translation = $translations->insert( 'block keyword', $msg );
if ( $add_reference ) {
$translation->addReference( $file );
}
}
break;
case 'styles':

Describe the solution you'd like

Replicate the approach used for ThemeJsonExtractor that uses schema for theme.json located in WordPress core codebsase:

private static function remote_get( $url ) {
if ( ! $url ) {
return '';
}
$headers = [ 'Content-type: application/json' ];
$options = [ 'halt_on_error' => false ];
$response = Utils\http_request( 'GET', $url, null, $headers, $options );
if (
! $response->success
|| 200 > (int) $response->status_code
|| 300 <= $response->status_code
) {
WP_CLI::debug( "Failed to download from URL {$url}", 'make-pot' );
return '';
}
return trim( $response->body );
}

The schema for block.json is located at https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/block-i18n.json.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions