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 #33546

Merged
merged 4 commits into from
Oct 16, 2023
Merged

Fix missing block translations #33546

merged 4 commits into from
Oct 16, 2023

Conversation

monsieur-z
Copy link
Contributor

@monsieur-z monsieur-z commented Oct 10, 2023

This PR work was originally done in #33326 but had to be reverted in #33431. It makes the exact same changes except that the editorScript key in block.json is now a script handle instead of a file path. This prevents multiple asset downloads.

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 [Status] In Progress [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Oct 10, 2023
@monsieur-z monsieur-z self-assigned this Oct 10, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 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, select your plugin, and enable the fix/block-translations-2 branch.

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

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

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 Oct 10, 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: November 7, 2023.
  • Scheduled code freeze: October 30, 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

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.

// `editorScript` is required for block.json to be valid and WordPress.org to be able
// to parse it before building the page at https://wordpress.org/plugins/jetpack/.
// Don't add other scripts or styles while block assets are still enqueued manually
// in the backend.
const result = {
...metadata,
editorScript: `file:../${ scriptName }.js`,
editorScript: `jetpack-blocks-editor`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prevent multiple asset downloads for now since the script is loaded manually on the backend. An editorScript key is required for the block.json file to be valid and for WordPress.org to be able to parse it.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This seems to test well for me. 🚢
You'll need one last rebase to be able to merge though.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Team Review labels Oct 13, 2023
@monsieur-z monsieur-z merged commit 71b9584 into trunk Oct 16, 2023
54 checks passed
@monsieur-z monsieur-z deleted the fix/block-translations-2 branch October 16, 2023 19:15
@github-actions github-actions bot removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Oct 16, 2023
@github-actions github-actions bot added this to the jetpack/12.7.1 milestone Oct 16, 2023
@ice9js ice9js modified the milestones: jetpack/12.7.1, jetpack/12.8 Oct 23, 2023
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

3 participants