From 8869518a119ad4eb5c4793bc64983856becb0f96 Mon Sep 17 00:00:00 2001 From: abaicus Date: Fri, 26 Jul 2024 09:32:58 +0300 Subject: [PATCH] fix: JS translations being loaded from the plugins directory --- inc/core/core_loader.php | 1 + inc/core/front_end.php | 21 +++++++++++++++++++++ tests/php/static-analysis-stubs/config.php | 1 + 3 files changed, 23 insertions(+) diff --git a/inc/core/core_loader.php b/inc/core/core_loader.php index 17adeeda4a..6db32b3578 100644 --- a/inc/core/core_loader.php +++ b/inc/core/core_loader.php @@ -176,6 +176,7 @@ function () { add_action( 'wp_enqueue_scripts', array( $front_end, 'enqueue_scripts' ) ); add_action( 'after_setup_theme', array( $front_end, 'setup_theme' ) ); add_action( 'widgets_init', array( $front_end, 'register_sidebars' ) ); + add_filter( 'load_script_translation_file', array( $front_end, 'fix_script_translation_files' ), 10, 3 ); } /** diff --git a/inc/core/front_end.php b/inc/core/front_end.php index b58c0d962a..3dc3844980 100644 --- a/inc/core/front_end.php +++ b/inc/core/front_end.php @@ -573,4 +573,25 @@ public function css_global_custom_colors( $current_styles, $context ) { return $current_styles; } + + /** + * Fix script translations language directory. + * + * @param string | false $file File path. + * @param string $handle Script handle. + * @param string $domain Script text domain. + * + * @return string | false + */ + public function fix_script_translation_files( $file, $handle, $domain ) { + if ( ! $file || $domain !== 'neve' ) { + return $file; + } + + if ( strpos( $file, WP_LANG_DIR . '/plugins' ) !== false ) { + $file = str_replace( WP_LANG_DIR . '/plugins', WP_LANG_DIR . '/themes', $file ); + } + + return $file; + } } diff --git a/tests/php/static-analysis-stubs/config.php b/tests/php/static-analysis-stubs/config.php index 17759006ed..621062a91e 100644 --- a/tests/php/static-analysis-stubs/config.php +++ b/tests/php/static-analysis-stubs/config.php @@ -5,3 +5,4 @@ define( 'WP_DEFAULT_THEME', 'neve' ); define( 'WP_PLUGIN_DIR', '/plugins' ); +define( 'WP_LANG_DIR', '/languages' );