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
Reusable block: Pluralize the message "Convert to regular blocks" depending on the number of blocks contained. #45819
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @janusqa! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
...s/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js
Outdated
Show resolved
Hide resolved
f580e63
to
a7435eb
Compare
const innerBlockCount = useSelect( | ||
( select ) => select( blockEditorStore ).getBlockCount( clientId ), | ||
[ clientId ] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're already selecting data from the block editor store, I would recommend combining these selectors. There's nothing wrong with using multiple useSelect
in components, but in this case, I think it makes sense to fetch data using a single selector.
Here's an example:
const { canRemove, innerBlockCount } = useSelect(
( select ) => {
const { canRemoveBlock, getBlockCount } =
select( blockEditorStore );
return {
canRemove: canRemoveBlock( clientId ),
innerBlockCount: getBlockCount( clientId ),
};
},
[ clientId ]
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mamaduka agreed. Will combine them in the other files as well if there is an per-existing select.
const innerBlockCount = useSelect( | ||
( select ) => select( blockEditorStore ).getBlockCount( clientId ), | ||
[ clientId ] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/WordPress/gutenberg/pull/45819/files#r1026355761, and for the .native.js
files as well, whenever applicable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll do this.
a7435eb
to
5f0661c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the changes in the WordPress app and work as expected, thank you @janusqa for introducing this enhancement 🙇.
However, I identified a couple of places that we'd also need to pluralize the message:
- https://github.com/WordPress/gutenberg/blob/5f0661c3f5718c10751b4d4ea26e00ab56e5c4cc/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js#L204-L206
- https://github.com/WordPress/gutenberg/blob/5f0661c3f5718c10751b4d4ea26e00ab56e5c4cc/packages/block-library/src/block/edit.native.js#L131-L132
Could we also update them? Thanks!
@fluiddot yes we can, will work on this. Thanks for your feedback. |
@fluiddot do you have a preference in the method used?
|
@janusqa I'd lean towards method 1 in order to properly extract the strings for translation in mobile, as we don't support yet plurals in the extraction process to include them in the apps translation pipeline. Alternatively, I'd like to share a third option where each string is referenced in its own
Third option:
|
Well well well, nicely done. this is very clean. I will use this one indeed. |
882847c
to
73eb85c
Compare
@fluiddot
It looks like we will need to tweak these test to look for the correct string depending on what the test creates as a reusable block. |
@janusqa Good point, in fact, that's the reason why the |
…ks to regular blocks
… block conversion, to be more clean and efficient by reducing the number of string translations needed from three to two
5d86e36
to
7b55aa1
Compare
@fluiddot Yes I should be able to. Test updated. Used a simplistic approach based on the assumption that we know the type of reusable block we will create in the test ahead of time. Let me know if we need something more dynamic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎊 ! I've tested the changes in the mobile app and they work as expected, thanks @janusqa for this fix.
I also gave a quick look at the web version to verify that it also works there. However, @Mamaduka since you're also assigned as a reviewer, let me know if you'd like to review the PR before merging it. Thanks!
Congratulations on your first merged pull request, @janusqa! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
…ending on the number of blocks contained. (WordPress#45819) * Properly pluralize 'Convert to regular blocks' label on menus * Properly pluralize 'Convert to regular blocks' label on menus * Properly pluralized the success message when converting reusable blocks to regular blocks * Refactored generation of pluralized success notification for resuable block conversion, to be more clean and efficient by reducing the number of string translations needed from three to two * Fixed two reusable block test to look for correct button label in singular form
Reusable block: Pluralize the message "Convert to regular blocks" depending on the number of blocks contained
What?
The action "Convert to regular blocks" is in plural form for all cases, including when the reusable block only contains a single block. It would be great if we detect the number of blocks contained and pluralize the message:
This PR fixes the issue by properly pluralizing the label where necessary.
Why?
It resolves #34749. The action "Convert to regular blocks" should be in singular if the reusable block only contains a single block.
How?
Based on @fluiddot advice the block count was determined by checking the inner blocks rendered within a reusable block, and the count was use to determine if to pluralize the label.
Testing Instructions
Screenshots or screencast