Skip to content

Commit

Permalink
Lazy load missing translation files (woocommerce#5112)
Browse files Browse the repository at this point in the history
* Lazo load missing translation files

* Lazy load cart translation files
  • Loading branch information
nielslange authored and jonny-bull committed Dec 16, 2021
1 parent 550755a commit a344571
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"lint:js:report": "npm run lint:js -- --output-file eslint_report.json --ext=js,ts,tsx --format json",
"lint:js-fix": "eslint assets/js --ext=js,jsx,ts,tsx --fix",
"lint:php": "composer run-script phpcs ./src",
"lint:php-fix": "composer run-script phpcbf ./src",
"package-plugin": "rimraf woocommerce-gutenberg-products-block.zip && ./bin/build-plugin-zip.sh",
"package-plugin:dev": "rimraf woocommerce-gutenberg-products-block.zip && ./bin/build-plugin-zip.sh -d",
"package-plugin:zip-only": "rimraf woocommerce-gutenberg-products-block.zip && ./bin/build-plugin-zip.sh -z",
Expand Down
19 changes: 19 additions & 0 deletions src/BlockTypes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,23 @@ protected function deep_sort_with_accents( $array ) {
protected function hydrate_from_api() {
$this->asset_data_registry->hydrate_api_request( '/wc/store/cart' );
}

/**
* Register script and style assets for the block type before it is registered.
*
* This registers the scripts; it does not enqueue them.
*/
protected function register_block_type_assets() {
parent::register_block_type_assets();
$blocks = [
'cart-blocks/express-payment--checkout-blocks/express-payment--checkout-blocks/payment',
'cart-blocks/line-items',
'cart-blocks/order-summary',
'cart-blocks/order-summary--checkout-blocks/billing-address--checkout-blocks/shipping-address',
'cart-blocks/checkout-button-frontend.js',
'cart-blocks/express-payment',
];
$chunks = preg_filter( '/$/', '-frontend', $blocks );
$this->register_chunk_translations( $chunks );
}
}
23 changes: 23 additions & 0 deletions src/BlockTypes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,27 @@ public static function include_token_id_with_payment_methods( $list_item, $token
}
return $list_item;
}

/**
* Register script and style assets for the block type before it is registered.
*
* This registers the scripts; it does not enqueue them.
*/
protected function register_block_type_assets() {
parent::register_block_type_assets();
$blocks = [
'checkout-blocks/express-payment',
'checkout-blocks/contact-information',
'checkout-blocks/shipping-address',
'checkout-blocks/billing-address',
'checkout-blocks/shipping-methods',
'checkout-blocks/payment',
'checkout-blocks/order-note',
'checkout-blocks/actions',
'checkout-blocks/terms',
'checkout-blocks/order-summary',
];
$chunks = preg_filter( '/$/', '-frontend', $blocks );
$this->register_chunk_translations( $chunks );
}
}

0 comments on commit a344571

Please sign in to comment.