Skip to content

Commit

Permalink
Update relative path for jetpack-mu-wpcom (#41861)
Browse files Browse the repository at this point in the history
* Fix: Ensure correct MD5 hash lookup for script translation files

A recent change renamed `vendor/` to `jetpack_vendor/`, causing mismatches
in generated MD5 hashes and resulting in missing translation JSON files.
#41185
  • Loading branch information
d-alleyne authored Feb 18, 2025
1 parent 4f4254f commit e8cf9c2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

i18n: fix missing script translations
21 changes: 21 additions & 0 deletions projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static function init() {
if ( did_action( 'jetpack_mu_wpcom_initialized' ) ) {
return;
}
// Apply temporary fix for translation path MD5 mismatch due to vendor -> jetpack_vendor change in https://github.com/Automattic/jetpack/pull/41185
add_filter( 'load_script_textdomain_relative_path', array( __CLASS__, 'fix_translation_relative_path_mismatch_wpcom_jetpack' ), 20, 2 );

// Shared code for src/features.
require_once self::PKG_DIR . 'src/common/index.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
Expand Down Expand Up @@ -89,6 +91,25 @@ public static function init() {
do_action( 'jetpack_mu_wpcom_initialized' );
}

/**
* Fixes translation file path MD5 mismatches caused by vendor -> jetpack_vendor migration.
*
* WordPress generates the translation file's MD5 hash based on the script's relative path.
* Since the path structure changed, we rewrite `jetpack_vendor/` back to `vendor/` before hashing.
*
* @param string|false $relative The relative script path (before MD5 hashing).
* @param string $src The script's original source path (unused).
* @return string|false Updated relative path that keeps WordPress's MD5 hash consistent.
*/
public static function fix_translation_relative_path_mismatch_wpcom_jetpack( $relative, $src ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
if ( $relative && str_contains( $relative, 'jetpack_vendor/automattic/jetpack-mu-wpcom/src/build/' ) ) {
// Rewrite "jetpack_vendor/" back to the original "vendor/" to maintain MD5 compatibility
$relative = str_replace( 'jetpack_vendor/', 'vendor/', $relative );
}

return $relative;
}

/**
* Load features that don't need any special loading considerations.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

i18n: fix missing script translations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

i18n: fix missing script translations

0 comments on commit e8cf9c2

Please sign in to comment.