Make WordPress Core


Ignore:
Timestamp:
06/16/2023 12:56:03 PM (12 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/tests/phpunit/tests/l10n/loadTextdomain.php

    r54669 r55928  
    301301        $this->assertSame( get_user_locale(), $this->locale );
    302302    }
     303
     304    /**
     305     * @ticket 58035
     306     *
     307     * @covers ::load_theme_textdomain
     308     */
     309    public function test_pre_load_textdomain_filter() {
     310        $override_load_textdomain_callback = new MockAction();
     311        add_filter( 'override_load_textdomain', array( $override_load_textdomain_callback, 'action' ) );
     312
     313        add_filter( 'pre_load_textdomain', '__return_true' );
     314        load_plugin_textdomain( 'wp-tests-domain' );
     315        remove_filter( 'pre_load_textdomain', '__return_true' );
     316
     317        $this->assertSame( 0, $override_load_textdomain_callback->get_call_count(), 'Expected override_load_textdomain not to be called.' );
     318    }
    303319}
Note: See TracChangeset for help on using the changeset viewer.