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

Commit

Permalink
Mini Cart block - fix translations handling (#6164)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu authored Mar 30, 2022
1 parent b4a4519 commit a559c8f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ protected function enqueue_data( array $attributes = [] ) {
}

$this->scripts_to_lazy_load['wc-block-mini-cart-component-frontend'] = array(
'src' => $script_data['src'],
'version' => $script_data['version'],
'src' => $script_data['src'],
'version' => $script_data['version'],
'translations' => $this->get_dependencies_translations(),
);

$this->asset_data_registry->add(
Expand Down Expand Up @@ -443,13 +444,12 @@ protected function get_cart_payload() {
}

/**
* Register script and style assets for the block type before it is registered.
*
* This registers the scripts; it does not enqueue them.
* The children blocks are register here because this block handles the loading of the frontend scripts.
* Prepare translations for inner blocks and dependencies.
*/
protected function register_block_type_assets() {
parent::register_block_type_assets();
protected function get_dependencies_translations() {
$wp_scripts = wp_scripts();
$translations = array();

$blocks = [
'mini-cart-contents-block/filled-cart',
'mini-cart-contents-block/empty-cart',
Expand All @@ -461,6 +461,15 @@ protected function register_block_type_assets() {
];
$chunks = preg_filter( '/$/', '-frontend', $blocks );

$this->register_chunk_translations( $chunks );
foreach ( $chunks as $chunk ) {
$handle = 'wc-blocks-' . $chunk . '-chunk';
$this->asset_api->register_script( $handle, $this->asset_api->get_block_asset_build_path( $chunk ), [], true );
$translations[] = $wp_scripts->print_translations( $handle, false );
wp_deregister_script( $handle );
}

$translations = array_filter( $translations );

return implode( '', $translations );
}
}

0 comments on commit a559c8f

Please sign in to comment.