Skip to content

Commit

Permalink
Asset CDN: Fix json translation loading (#10982)
Browse files Browse the repository at this point in the history
When the static asset CDN of Jetpack is loaded, the translations for Gutenberg don'tt load properly because the filename is generated for a wrong path.

Also fixes Automattic/wp-calypso#29309

This has been extensively discussed in https://core.trac.wordpress.org/ticket/45528

#### Changes proposed in this Pull Request:

* This implements the filter that has been introduced into Core.

#### Testing instructions:

Prequisit: WordPress 5.0.2(alpha) or trunk

1. Set your WordPress to another language than English.
2. Activate Jetpack Static Asset CDN.
3. Potentially add a filter to your WordPress if it's running trunk (see #10102)
4. Create a new post to open Gutenberg and observe broken translations.
5. Activate the patch: Translations should now load after a reload.

#### Proposed changelog entry for your changes:

* Fixes loading of the Block Editor UI translations when Static Asset CDN is used (requires WordPress 5.0.2)
  • Loading branch information
akirk authored and jeherve committed Dec 18, 2018
1 parent d0d3f2a commit 8bb8a1b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/photon-cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function go() {
add_action( 'admin_print_scripts', array( __CLASS__, 'cdnize_assets' ) );
add_action( 'admin_print_styles', array( __CLASS__, 'cdnize_assets' ) );
add_action( 'wp_footer', array( __CLASS__, 'cdnize_assets' ) );
add_filter( 'load_script_textdomain_relative_path', array( __CLASS__, 'fix_script_relative_path' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -83,6 +84,17 @@ public static function cdnize_assets() {
}
}

/**
* Ensure use of the correct relative path when determining the JavaScript file names.
*
* @param string $relative The relative path of the script. False if it could not be determined.
* @param string $src The full source url of the script.
* @return string The expected relative path for the CDN-ed URL.
*/
public static function fix_script_relative_path( $relative, $src ) {
return substr( $src, 1 + strpos( $src, '/wp-includes/' ) );
}

/**
* Sets up CDN URLs for supported plugin assets.
*
Expand Down

0 comments on commit 8bb8a1b

Please sign in to comment.