Fixes js translated files by adding inline enqueue of translation script.
This commit is contained in:
parent
dae65fc5b1
commit
8acfc2c78f
|
@ -4278,9 +4278,9 @@
|
||||||
"integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA=="
|
"integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA=="
|
||||||
},
|
},
|
||||||
"json5": {
|
"json5": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
||||||
"integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==",
|
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"jsprim": {
|
"jsprim": {
|
||||||
|
|
|
@ -7,16 +7,16 @@ const TAINACAN_BLOCKS = [
|
||||||
'items-list' => [],
|
'items-list' => [],
|
||||||
'collections-list' => [],
|
'collections-list' => [],
|
||||||
'search-bar' => [],
|
'search-bar' => [],
|
||||||
'facets-list' => [],
|
'facets-list' => [ 'set_script_translations' => true ],
|
||||||
'dynamic-items-list' => [],
|
'dynamic-items-list' => [ 'set_script_translations' => true ],
|
||||||
'carousel-items-list' => [],
|
'carousel-items-list' => [ 'set_script_translations' => true ],
|
||||||
'carousel-terms-list' => [],
|
'carousel-terms-list' => [ 'set_script_translations' => true ],
|
||||||
'carousel-collections-list' => [],
|
'carousel-collections-list' => [ 'set_script_translations' => true ],
|
||||||
'related-items-list' => [],
|
'related-items-list' => [],
|
||||||
'terms-list' => [],
|
'terms-list' => [],
|
||||||
'faceted-search' => [],
|
'faceted-search' => [],
|
||||||
'item-submission-form' => [],
|
'item-submission-form' => [],
|
||||||
'item-gallery' => ['render_callback' => 'tainacan_blocks_render_items_gallery'],
|
'item-gallery' => [ 'set_script_translations' => true, 'render_callback' => 'tainacan_blocks_render_items_gallery' ],
|
||||||
'item-metadata-sections' => ['render_callback' => 'tainacan_blocks_render_metadata_sections'],
|
'item-metadata-sections' => ['render_callback' => 'tainacan_blocks_render_metadata_sections'],
|
||||||
'item-metadata-section' => ['render_callback' => 'tainacan_blocks_render_metadata_section'],
|
'item-metadata-section' => ['render_callback' => 'tainacan_blocks_render_metadata_section'],
|
||||||
'item-metadata' => ['render_callback' => 'tainacan_blocks_render_item_metadata'],
|
'item-metadata' => ['render_callback' => 'tainacan_blocks_render_item_metadata'],
|
||||||
|
@ -152,6 +152,18 @@ function tainacan_blocks_register_block($block_slug, $options = []) {
|
||||||
);
|
);
|
||||||
$register_params['style'] = $block_slug;
|
$register_params['style'] = $block_slug;
|
||||||
|
|
||||||
|
// Makes sure translations that use wp.i18n work with our lazy loading strategy
|
||||||
|
if ( isset($options['set_script_translations']) && $options['set_script_translations'] ) {
|
||||||
|
wp_register_script(
|
||||||
|
'tainacan-chunks-' . $block_slug . '-theme',
|
||||||
|
$TAINACAN_BASE_URL . '/assets/js/tainacan-chunks-' . $block_slug . '-theme.js',
|
||||||
|
array('wp-i18n'),
|
||||||
|
$TAINACAN_VERSION
|
||||||
|
);
|
||||||
|
wp_set_script_translations( 'tainacan-chunks-' . $block_slug . '-theme', 'tainacan' );
|
||||||
|
wp_add_inline_script( 'wp-i18n', wp_scripts()->print_translations('tainacan-chunks-' . $block_slug . '-theme', false) );
|
||||||
|
}
|
||||||
|
|
||||||
// Registers the new block
|
// Registers the new block
|
||||||
if (function_exists('register_block_type')) {
|
if (function_exists('register_block_type')) {
|
||||||
if ( version_compare( $wp_version, '5.8-RC', '>=') )
|
if ( version_compare( $wp_version, '5.8-RC', '>=') )
|
||||||
|
@ -226,6 +238,8 @@ function tainacan_blocks_add_common_theme_scripts() {
|
||||||
$TAINACAN_VERSION
|
$TAINACAN_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
wp_set_script_translations( 'tainacan-blocks-common-scripts', 'tainacan' );
|
||||||
|
|
||||||
$block_settings = tainacan_blocks_get_plugin_js_settings();
|
$block_settings = tainacan_blocks_get_plugin_js_settings();
|
||||||
$plugin_settings = \Tainacan\Admin::get_instance()->get_admin_js_localization_params();
|
$plugin_settings = \Tainacan\Admin::get_instance()->get_admin_js_localization_params();
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ performWhenDocumentIsLoaded(() => {
|
||||||
moduleImport: name => import(
|
moduleImport: name => import(
|
||||||
/* webpackMode: "lazy" */
|
/* webpackMode: "lazy" */
|
||||||
/* webpackInclude: /theme\.js$/ */
|
/* webpackInclude: /theme\.js$/ */
|
||||||
/* webpackChunkName: "tainacan-chunks-" */
|
/* webpackChunkName: "tainacan-chunks-[request]" */
|
||||||
`${name}`
|
`${name}`
|
||||||
)
|
)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
@ -28,7 +28,7 @@ performWhenDocumentIsLoaded(() => {
|
||||||
moduleImport: name => import(
|
moduleImport: name => import(
|
||||||
/* webpackMode: "lazy" */
|
/* webpackMode: "lazy" */
|
||||||
/* webpackInclude: /main\.js$/ */
|
/* webpackInclude: /main\.js$/ */
|
||||||
/* webpackChunkName: "tainacan-chunks-" */
|
/* webpackChunkName: "tainacan-chunks-[request]" */
|
||||||
`${name}`
|
`${name}`
|
||||||
)
|
)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
Loading…
Reference in New Issue