Skip to content

Commit

Permalink
Merge pull request #873 from humanmade/core-6.5.0-afterburner
Browse files Browse the repository at this point in the history
Fix Afterburner translations with WordPress 6.5.0
  • Loading branch information
kovshenin authored Apr 20, 2024
2 parents 12f0c70 + 49730b9 commit 3a7aba3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions inc/afterburner/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
function bootstrap() : void {
add_filter( 'qm/outputter/html', __NAMESPACE__ . '\\register_qm_output_html' );
add_filter( 'pre_load_textdomain', __NAMESPACE__ . '\\pre_load_textdomain', 10, 4 );
}

/**
Expand All @@ -26,3 +27,53 @@ function register_qm_output_html( array $output ) : array {

return $output;
}

/**
* Short-circuit load_textdomain to make sure Afterburner's MO is used.
*
* @param bool|null $load Return non-null to short-circuit.
* @param string $domain The text domain being loaded.
* @param string $mofile The path the the .mo file being loaded.
* @param string|null $locale The local being loaded.
*
* @return null|bool True if loaded successfully, false if could not load, null to continue core's routine.
*/
function pre_load_textdomain( $load, $domain, $mofile, $locale ) {
global $wp_textdomain_registry, $l10n;

if ( version_compare( $GLOBALS['wp_version'], '6.5.0', '<' ) ) {
return $load;
}

if ( (bool) apply_filters( 'override_load_textdomain', false, $domain, $mofile, $locale ) ) {
return true;
}

do_action( 'load_textdomain', $domain, $mofile );

$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );

if ( ! is_readable( $mofile ) ) {
return false;
}

if ( ! $locale ) {
$locale = determine_locale();
}

$mo = new \MO();
if ( ! $mo->import_from_file( $mofile ) ) {
$wp_textdomain_registry->set( $domain, $locale, false );

return false;
}

if ( isset( $l10n[ $domain ] ) ) {
$mo->merge_with( $l10n[ $domain ] );
}

$l10n[ $domain ] = &$mo;
$wp_textdomain_registry->set( $domain, $locale, dirname( $mofile ) );
return true;
}

0 comments on commit 3a7aba3

Please sign in to comment.