Automattic\WooCommerce\Blocks\BlockTypes

AbstractBlock::register_chunk_translations │ protected │ WC 1.0

Injects Chunk Translations into the page so translations work for lazy loaded components.

The chunk names are defined when creating lazy loaded components using webpackChunkName.

Method of the class: AbstractBlock{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->register_chunk_translations( $chunks );
$chunks(string[]) (required)
Array of chunk names.

AbstractBlock::register_chunk_translations() code WC 11.1.2

protected function register_chunk_translations( $chunks ) {
	$script_handle = $this->get_block_type_script( 'handle' );
	if ( ! is_string( $script_handle ) || '' === $script_handle ) {
		return;
	}
	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 );
		wp_add_inline_script(
			$script_handle,
			wp_scripts()->print_translations( $handle, false ),
			'before'
		);
		wp_deregister_script( $handle );
	}
}