Make WordPress Core


Ignore:
Timestamp:
06/16/2023 12:56:03 PM (18 months ago)
Author:
swissspidy
Message:

I18N: Allow to short-circuit load_textdomain().

Introduces a new pre_load_textdomain filter, which is useful for plugins to develop and test alternative loading/caching strategies for translations. This brings consistency with the existing pre_load_script_translations filter for JavaScript translations.

Props ocean90, swissspidy.
Fixes #58035.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r55865 r55928  
    717717
    718718    $l10n_unloaded = (array) $l10n_unloaded;
     719
     720    /**
     721     * Filters whether to short-circuit loading .mo file.
     722     *
     723     * Returning a non-null value from the filter will effectively short-circuit
     724     * the loading, returning the passed value instead.
     725     *
     726     * @since 6.3.0
     727     *
     728     * @param bool|null   $loaded The result of loading a .mo file. Default null.
     729     * @param string      $domain Text domain. Unique identifier for retrieving translated strings.
     730     * @param string      $mofile Path to the MO file.
     731     * @param string|null $locale Locale.
     732     */
     733    $loaded = apply_filters( 'pre_load_textdomain', null, $domain, $mofile, $locale );
     734    if ( null !== $loaded ) {
     735        if ( true === $loaded ) {
     736            unset( $l10n_unloaded[ $domain ] );
     737        }
     738
     739        return $loaded;
     740    }
    719741
    720742    /**
Note: See TracChangeset for help on using the changeset viewer.