Description
Part of #16209.
There are some issues related to internationalization (i18n) support in newly introduced block.json
metadata files that still need to be resolved.
There is a proposal in block registration metadata document that we still need to implement:
https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#internationalization
The good news is that WP-CLI has implemented (wp-cli/i18n-command#210) native support for translatable strings extraction from block.json
file in i18n
command. It was based on the aforementioned RFC. It still needs to be released though.
JavaScript
- JSON imports work only in Node.js or with webpack tool. In Gutenberg, we use a custom plugin that inlines JSON in JavaScript as a plain object. We should decide whether we add the same plugin to the shared Babel preset (
@wordpress/babel-preset-default
) distributed as part of WordPress packages. - We miss the logic that wraps translatable fields with i18n functions, it still needs to be added. In the past, there was a failed attempt to build a Babel macro that would address both points but it wasn’t as straightforward as expected. We were afraid it could be a point of bugs when not configured properly. Related PR: Babel macro: Add new Babel macro which handles block.json file transformation #16088.
PHP (Implemented)
The same issue applies to i18n handling on the PHP side of things. There was a new register_block_type_from_metadata
utility function added in #20794 to make it possible to register a new block type using block.json
metadata file. It's still missing i18n support.
Temporary support
The temporary approach for 3rd party blocks that want to use register_block_type_from_metadata
would be to keep everything that doesn't need to be translated in block.json
and put the rest as additional params passed with 2nd argument, e.g.:
register_block_type_from_metadata( __DIR__, array(
'title' => _x( 'My block', 'block title', 'my-plugin-domain' ),
'description' => _x( 'My block is fantastic!', 'block description', 'my-plugin-domain' ),
'keywords' => array( _x( 'fantastic', 'block keywords', 'my-plugin-domain' ) ),
) );
Activity