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

Fix missing block translations #33326

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Fix missing block translations #33326

merged 3 commits into from
Sep 28, 2023

Conversation

monsieur-z
Copy link
Contributor

@monsieur-z monsieur-z commented Sep 27, 2023

Fixes p1694788078746839-slack-CDLH4C1UZ

Proposed changes:

#32698, #32815, and #33073 introduced localization issues for simple sites: block titles and descriptions were displayed in English no matter the user's selected language. This PR fixes it.

The blocks involved are: Business Hours, AI Chat, Amazon, Blogroll, Google Docs Embed (Google Docs, Google Sheets, and Google Slides), Recipe, Create with Voice.

In more details:

  • On the server side, block localization requires register_block_type to be called with the path to block.json or its parent directory. jetpack_register_block is updated accordingly.
  • On the client side, registerBlockType requires to be called with the metadata object. registerJetpackBlock is updated to allow that.
  • The above change requires to lower the API version of some blocks, so that their render functions work correctly.
  • It also requires the registration of the Recipe block to happen on an init action, to prevent an exception being thrown.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

n/a

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Regression Testing

  • Enable beta blocks in the Jetpack constants section if you're using a JN site, or by adding define( 'JETPACK_BLOCKS_VARIATION', 'beta' ); to your wp-config.php otherwise.
  • Create a new post.
  • Notice that the aforementioned blocks are not broken.

Localization Testing

  • Download this branch.
  • Build the plugin: jetpack build plugins/jetpack.
  • Remote sync the plugin with your sandbox (see PCYsg-eg0-p2).
  • Change the language of your WordPress.com account to something different than English.
  • In WordPress.com, select the site linked to your sandbox and create a new post.
  • In the block inserter, notice that the block titles and descriptions for the blocks above are translated.

Blocks info translated to French
Screenshot 2023-09-19 at 9 47 38 AM
Screenshot 2023-09-19 at 9 47 49 AM
Screenshot 2023-09-19 at 9 47 57 AM
Screenshot 2023-09-19 at 9 48 04 AM
Screenshot 2023-09-19 at 9 48 15 AM
Screenshot 2023-09-19 at 9 48 23 AM
Screenshot 2023-09-19 at 9 48 31 AM

@monsieur-z monsieur-z added [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Status] Needs Team Review labels Sep 27, 2023
@monsieur-z monsieur-z added this to the jetpack/12.7 milestone Sep 27, 2023
@monsieur-z monsieur-z requested a review from a team September 27, 2023 01:41
@monsieur-z monsieur-z self-assigned this Sep 27, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 27, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta > Jetpack and enable the fix/block-translations branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack fix/block-translations
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

github-actions bot commented Sep 27, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

  • Next scheduled release: October 10, 2023.
  • Scheduled code freeze: October 9, 2023.

@@ -30,7 +30,7 @@ type BlockSettingsProps = {
};

export const isAiAssistantSupportExtensionEnabled =
window?.Jetpack_Editor_Initial_State.available_blocks?.[ AI_ASSISTANT_SUPPORT_NAME ];
window?.Jetpack_Editor_Initial_State?.available_blocks?.[ AI_ASSISTANT_SUPPORT_NAME ];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required to avoid exception being thrown.

@@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required anymore.

'render_callback' => array( 'Automattic\\Jetpack\\Extensions\\Recipe\\Jetpack_Recipe_Block', 'render' ),
)
);
add_action(
Copy link
Contributor Author

@monsieur-z monsieur-z Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap blocks registration in an init action callback.

Comment on lines 15 to 27
Blocks::jetpack_register_block(
__DIR__,
array(
'render_callback' => array( 'Automattic\\Jetpack\\Extensions\\Recipe\\Jetpack_Recipe_Block', 'render' ),
)
);

Blocks::jetpack_register_block(
'jetpack/recipe-details',
array(
'parent' => array( 'jetpack/recipe' ),
)
);
Blocks::jetpack_register_block(
__DIR__,
array(
'render_callback' => array( 'Automattic\\Jetpack\\Extensions\\Recipe\\Jetpack_Recipe_Block', 'render' ),
)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended that you're making the same call twice here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! Thank you.

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@monsieur-z monsieur-z merged commit b8d9424 into trunk Sep 28, 2023
54 checks passed
@monsieur-z monsieur-z deleted the fix/block-translations branch September 28, 2023 19:09
monsieur-z added a commit that referenced this pull request Oct 2, 2023
kraftbj pushed a commit that referenced this pull request Oct 2, 2023
mikestottuk pushed a commit that referenced this pull request Oct 6, 2023
@monsieur-z monsieur-z mentioned this pull request Oct 11, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] AI Assistant [Block] AI Chat [Block] Amazon [Block] Business Hours [Block] Recipe [Extension] AI Content Lens [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Package] Blocks [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants