Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block API: Add i18n support to block.json metadata file #23636

Closed
gziolo opened this issue Jul 2, 2020 · 8 comments · Fixed by #30293
Closed

Block API: Add i18n support to block.json metadata file #23636

gziolo opened this issue Jul 2, 2020 · 8 comments · Fixed by #30293
Assignees
Labels
[Feature] Block API API that allows to express the block paradigm. Internationalization (i18n) Issues or PRs related to internationalization efforts [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@gziolo
Copy link
Member

gziolo commented Jul 2, 2020

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

  1. 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.
  2. 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' ) ),
) );
@gziolo gziolo added [Feature] Block API API that allows to express the block paradigm. Internationalization (i18n) Issues or PRs related to internationalization efforts labels Jul 2, 2020
@gziolo gziolo added the [Priority] High Used to indicate top priority items that need quick attention label Jul 8, 2020
@swissspidy
Copy link
Member

What's also missing here is the whole WordPress.org part and what the translation files will look like. We currently use JSON files with MD5 hashes for JS translations, and PO files for PHP translations. Where do block translations live?

@noisysocks
Copy link
Member

👋 ended up here because of the [Priority] High label. What's the status of this one? Should we prioritise it for 5.7?

@gziolo
Copy link
Member Author

gziolo commented Jan 6, 2021

Yes, that would be great. In fact, it requires changes on the WordPress core side because we lack filters in register_block_type_from_metadata. Relate proposal for filters in WordPress/wordpress-develop#821.

@jorgefilipecosta works on a similar proposal for a theme.json file in #27380. It should help to drive this integration. I don't think it's a blocker though 😃

@noisysocks, do you plan to take care of it or you only wanted to triage labels?

@noisysocks noisysocks added the [Type] Enhancement A suggestion for improvement. label Jan 7, 2021
@noisysocks
Copy link
Member

@noisysocks, do you plan to take care of it or you only wanted to triage labels?

Just triaging! This issue will need an owner.

@gziolo gziolo self-assigned this Jan 12, 2021
@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Jan 12, 2021
@gziolo
Copy link
Member Author

gziolo commented Jan 13, 2021

I opened PR targeting the WordPress core: WordPress/wordpress-develop#868.

nylen pushed a commit to nylen/wordpress-develop-svn that referenced this issue Jan 19, 2021
Related Gutenberg issue: WordPress/gutenberg#23636.
Related WP-CLI PR: wp-cli/i18n-command#210.
Related documentation proposal: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/block-api/block-metadata.md#internationalization-not-implemented

Adds programatic i18n support to `register_block_type_from_metadata` function for block settings registered from `block.json` file that provides `textdomain` field.


Props swissspidy, ocean90.
Fixes #52301.



git-svn-id: https://develop.svn.wordpress.org/trunk@49981 602fd350-edb4-49c9-b593-d223f7449a82
pento pushed a commit to WordPress/wordpress-develop that referenced this issue Jan 19, 2021
Related Gutenberg issue: WordPress/gutenberg#23636.
Related WP-CLI PR: wp-cli/i18n-command#210.
Related documentation proposal: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/block-api/block-metadata.md#internationalization-not-implemented

Adds programatic i18n support to `register_block_type_from_metadata` function for block settings registered from `block.json` file that provides `textdomain` field.


Props swissspidy, ocean90.
Fixes #52301.



git-svn-id: https://develop.svn.wordpress.org/trunk@49981 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Jan 19, 2021
Related Gutenberg issue: WordPress/gutenberg#23636.
Related WP-CLI PR: wp-cli/i18n-command#210.
Related documentation proposal: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/block-api/block-metadata.md#internationalization-not-implemented

Adds programatic i18n support to `register_block_type_from_metadata` function for block settings registered from `block.json` file that provides `textdomain` field.


Props swissspidy, ocean90.
Fixes #52301.


Built from https://develop.svn.wordpress.org/trunk@49981


git-svn-id: http://core.svn.wordpress.org/trunk@49682 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this issue Jan 19, 2021
Related Gutenberg issue: WordPress/gutenberg#23636.
Related WP-CLI PR: wp-cli/i18n-command#210.
Related documentation proposal: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/block-api/block-metadata.md#internationalization-not-implemented

Adds programatic i18n support to `register_block_type_from_metadata` function for block settings registered from `block.json` file that provides `textdomain` field.


Props swissspidy, ocean90.
Fixes #52301.


Built from https://develop.svn.wordpress.org/trunk@49981


git-svn-id: https://core.svn.wordpress.org/trunk@49682 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@gziolo
Copy link
Member Author

gziolo commented Jan 20, 2021

On the PHP side of things, everything is sorted out with https://core.trac.wordpress.org/ticket/52301. You can now register a block type using:

register_block_type_from_metadata( __DIR__ );

It will load the block.json file from the current directory and translate fields that are listed as translatable when the textdomain is provided.

I plan to update the client-side code to ensure it doesn't override the block metadata registered on the server for core blocks.

@noisysocks
Copy link
Member

Removing this from the 5.7 board per this comment from @gziolo:

#23636 won’t have more items in WP 5.7, it requires some more fiddling on the Gutenberg side to make it work and it depends on the changes that are included in WP core for 5.7.

@gziolo
Copy link
Member Author

gziolo commented Mar 26, 2021

I started JS implementation in #30293.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. Internationalization (i18n) Issues or PRs related to internationalization efforts [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants