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

Correctly load JS translations from WC core #5910

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions woocommerce-gutenberg-products-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ function woocommerce_blocks_get_i18n_data_json( $translations, $file, $handle, $
return $translations;
}

$handle_filename = basename( $wp_scripts->registered[ $handle ]->src );
$handle_src = explode( '/build/', $wp_scripts->registered[ $handle ]->src );
$handle_filename = $handle_src[1];
$locale = determine_locale();
$lang_dir = WP_LANG_DIR . '/plugins';

Expand Down Expand Up @@ -203,7 +204,13 @@ function woocommerce_blocks_get_i18n_data_json( $translations, $file, $handle, $
} )( "{$domain}", {$json_translations} );
JS;

printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); // phpcs:ignore
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NoExplicitVersion
wp_register_script( $handle_filename, '', array( 'wp-i18n' ), false, true );
wp_enqueue_script( $handle_filename );
wp_add_inline_script(
$handle_filename,
$output
);

// Finally, short circuit the pre_load_script_translations hook by returning
// the translation JSON from the feature plugin, if it exists so this hook
Expand Down