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 blocks missing translations in simple sites #33190

Closed
wants to merge 3 commits into from

Conversation

monsieur-z
Copy link
Contributor

@monsieur-z monsieur-z commented Sep 19, 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, Recipe, Create with Voice.

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:

  • Review the code
  • Regression testing:
    • Spin up a test site with this PR. This could be a self-hosted site or a simple site.
    • 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 self-assigned this Sep 19, 2023
@github-actions github-actions bot added [Block] AI Chat [Block] Business Hours [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Sep 19, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 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 3, 2023.
  • Scheduled code freeze: September 25, 2023.

Mu Wpcom plugin:

  • Next scheduled release: October 3, 2023.
  • Scheduled code freeze: September 25, 2023.

@github-actions
Copy link
Contributor

Are you an Automattician? The PR will need to be tested on WordPress.com. This comment will be updated with testing instructions as soon the build is complete.

@@ -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

@monsieur-z monsieur-z Sep 19, 2023

Choose a reason for hiding this comment

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

Metadata are added to settings in registerJetpackBlockFromMetadata anyway.

@@ -1,10 +1,10 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"apiVersion": 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the changes brought to registerJetpackBlockFromMetadata , the implementation of the edit function (I believe) requires the block to use the first version of the API.

@github-actions github-actions bot added [Package] Jetpack mu wpcom WordPress.com Features [Package] Sync [Plugin] mu wpcom jetpack-mu-wpcom plugin labels Sep 19, 2023
@monsieur-z monsieur-z changed the title Fix blocks localization Fix blocks missing translations in simple sites Sep 19, 2023
Copy link
Contributor

@andrii-lysenko andrii-lysenko left a comment

Choose a reason for hiding this comment

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

LGTM!

I think this can be merged after issues with the builds are resolved.

for ( const prop in props ) {
if ( LOCALIZED_BLOCK_PROPERTIES.includes( prop ) ) {
// eslint-disable-next-line
result[ prop ] = _x( props[ prop ], null, metadata.textdomain || DEFAULT_TEXTDOMAIN );
Copy link
Contributor

@anomiex anomiex Sep 21, 2023

Choose a reason for hiding this comment

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

(most of this is already known to the people involved via Slack discussions, but to close the loop I'll repeat it here)

I think this only accidentally works if your translation files still have the translations from

title: __( 'Business Hours', 'jetpack' ),
description: __( 'Display opening hours for your business.', 'jetpack' ),
that were removed in #32698.

WordPress intends for the translation to happen on the PHP side during block registration (here), then the already-translated texts are sent to JS via a generated call to wp.blocks.unstable__bootstrapServerSideBlockDefinitions (here, here, here, or here).

That PHP code path is only reached when using register_block_type_from_metadata(), or passing a path to the block.json to register_block_type(). We instead pass a WP_Block_Type object. So we'd either need to change our code to pass the block.json path, or duplicate the relevant logic (plus any other needed logic for any other core block.json registeration features) when creating our WP_Block_Type.

@monsieur-z
Copy link
Contributor Author

Close in favour of #33326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] AI Chat [Block] Business Hours [Package] Jetpack mu wpcom WordPress.com Features [Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants