Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix missing translations in inspector (#6737)
Browse files Browse the repository at this point in the history
* Try registering the "cart taxes" inner block

Registering server side. This example isn't working, but I'm pushing to
share it and see what's wrong with this implementation.

* Fix registering the cart taxes inner block issue

* Update translation script loading

* Remove unnecessary JS translation

The translation should work fine by getting the title & description from
the `block.json` file

* Put back the initial code in the 'Cart Taxes' inner block

We didn't provide the correct `block.json` file path server side,
that's why the `metadata` wasn't correctly registered

* Generate `block.json`files for inner blocks

This is the first step on fixing the missing translations of `metadata`
in `block.json` files

* Set the folder name exactly the same as the inner block name

We are doing this first test for the `Cart taxes` inner block.

The `Block` & its containing folder need to have the same name for:
- Consistency
- We use the `Block` name to get the file Path

* Update imports after folder renaming

* Get block name directly from the JSON metadata

Getting the block name from the JSON metadata is less error prone than
extracting it from the file path.

And no need to rename all our `inner-blocks` to get the correct
`block.json` path

* Revert folder naming change of `Cart taxes` inner block

Since we are getting the `block` name directly from the `block.json`
metadata instead of extracting it from the file path, there is no need
to keep their names in sync anymore

* Fix missing translations for the `Cart Subtotal` Block

* Register only the client-side settings on the client

When the block is registered on the server, you only need to register
the client-side settings on the client using the same block’s name.
See [docs](https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#javascript-client-side).

* Add schema validation to `block.json`

Development is improved by using a defined schema definition file.
Supported editors can provide help like tooltips, autocomplete, and
schema validation.

* Use the same `editor_script` as the parent block

This prevents WordPress from generating script tags to inexistant
inner blocks JS files

* Add C&C inner blocks in Cart.php & Checkout.php

This is a refactoring to keep the block types controller file less
overloaded

* Fix all Cart inner blocks missing translations

* Create the "AbstractInnerBlock" class

The "Inner Blocks" will use their parent's script, so no need to create
new scripts for each one of them

And, our "Inner Blocks" should always be registered using the metadata file

* Update the "Inner Blocks" PHP classes

* Fix PHP lint erros & update function description

* Fix missing translations bug for all Checkout Inner Blocks

* Update src/BlockTypes/Checkout.php

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>

* skip lazy loaded scripts

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
  • Loading branch information
tarhi-saad and senadir authored Aug 1, 2022
1 parent 28c2a68 commit 9d57054
Show file tree
Hide file tree
Showing 110 changed files with 897 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
},
"parent": [ "woocommerce/cart-totals-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import { Icon, payment } from '@wordpress/icons';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
icon: {
src: (
<Icon
icon={ payment }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
} );
registerFeaturePluginBlockType(
'woocommerce/cart-accepted-payment-methods-block',
{
icon: {
src: (
<Icon
icon={ payment }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"parent": [ "woocommerce/cart-totals-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-express-payment-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"parent": [ "woocommerce/filled-cart-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-items-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"parent": [ "woocommerce/cart-items-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-line-items-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"parent": [ "woocommerce/cart-totals-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
icon: {
src: (
<Icon
icon={ tag }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
} );
registerFeaturePluginBlockType(
'woocommerce/cart-order-summary-coupon-form-block',
{
icon: {
src: (
<Icon
icon={ tag }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
} );
registerFeaturePluginBlockType(
'woocommerce/cart-order-summary-discount-block',
{
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-fee-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
} );
registerFeaturePluginBlockType(
'woocommerce/cart-order-summary-heading-block',
{
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
*/
import { Edit, Save } from './edit';
import attributes from './attributes';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
attributes,
edit: Edit,
save: Save,
} );
registerFeaturePluginBlockType(
'woocommerce/cart-order-summary-shipping-block',
{
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
attributes,
edit: Edit,
save: Save,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
} );
registerFeaturePluginBlockType(
'woocommerce/cart-order-summary-subtotal-block',
{
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"parent": [ "woocommerce/cart-order-summary-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
*/
import { Edit, Save } from './edit';
import attributes from './attributes';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-taxes-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
},
"parent": [ "woocommerce/filled-cart-block" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/cart-totals-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"parent": [ "woocommerce/cart" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';

registerFeaturePluginBlockType( metadata, {
registerFeaturePluginBlockType( 'woocommerce/empty-cart-block', {
icon: {
src: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"parent": [ "woocommerce/cart" ],
"textdomain": "woo-gutenberg-products-block",
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2
}
Loading

0 comments on commit 9d57054

Please sign in to comment.