WordPress.org

Make WordPress Core

Ticket #37997: 37997.diff

File 37997.diff, 3.4 KB (added by swissspidy, 4 years ago)
  • src/wp-includes/l10n.php

    diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
    index aaa7611..1e4b4b5 100644
    function unload_textdomain( $domain ) { 
    615615                return true;
    616616        }
    617617
     618        $l10n_unloaded[ $domain ] = true;
     619
    618620        return false;
    619621}
    620622
    function load_child_theme_textdomain( $domain, $path = false ) { 
    804806 * @access private
    805807 *
    806808 * @see get_translations_for_domain()
    807  * @global array $l10n_unloaded An array of all text domains that have been unloaded again.
    808809 *
    809810 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    810811 * @return bool True when the textdomain is successfully loaded, false otherwise.
    811812 */
    812813function _load_textdomain_just_in_time( $domain ) {
    813         global $l10n_unloaded;
    814 
    815         $l10n_unloaded = (array) $l10n_unloaded;
    816 
    817814        static $cached_mofiles = null;
    818815
    819816        // Short-circuit if domain is 'default' which is reserved for core.
    820         if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) {
     817        if ( 'default' === $domain || is_textdomain_unloaded( $domain ) ) {
    821818                return false;
    822819        }
    823820
    function _load_textdomain_just_in_time( $domain ) { 
    847844                return load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile );
    848845        }
    849846
     847        /*
     848         * If we've gotten this far, there are no translations for this domain.
     849         *
     850         * Unload it to avoid further calls to this function for it.
     851         */
     852        unload_textdomain( $domain );
     853
    850854        return false;
    851855}
    852856
    function _load_textdomain_just_in_time( $domain ) { 
    864868 */
    865869function get_translations_for_domain( $domain ) {
    866870        global $l10n;
     871
    867872        if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) {
    868873                return $l10n[ $domain ];
    869874        }
    function get_translations_for_domain( $domain ) { 
    881886 *
    882887 * @since 3.0.0
    883888 *
    884  * @global array $l10n
     889 * @global array $l10n An array of all currently loaded text domains.
    885890 *
    886891 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    887892 * @return bool Whether there are translations.
    function is_textdomain_loaded( $domain ) { 
    892897}
    893898
    894899/**
     900 * Whether a textdomain has been unloaded.
     901 *
     902 * @since 4.7.0
     903 *
     904 * @global array $l10n_unloaded An array of all text domains that have been unloaded.
     905 *
     906 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     907 * @return bool Whether domain has been unloaded.
     908 */
     909function is_textdomain_unloaded( $domain ) {
     910        global $l10n_unloaded;
     911
     912        return isset( $l10n_unloaded[ $domain ] );
     913}
     914
     915/**
    895916 * Translates role name.
    896917 *
    897918 * Since the role names are in the database and not in the source there
    function is_rtl() { 
    11481169                return false;
    11491170        }
    11501171        return $wp_locale->is_rtl();
    1151 }
    1152  No newline at end of file
     1172}
  • tests/phpunit/tests/l10n.php

    diff --git tests/phpunit/tests/l10n.php tests/phpunit/tests/l10n.php
    index f1048aa..054f221 100644
    class Tests_L10n extends WP_UnitTestCase { 
    4040                $file = DIR_TESTDATA . '/pomo/simple.mo';
    4141                $this->assertTrue( load_textdomain( 'wp-tests-domain', $file ) );
    4242                $this->assertTrue( is_textdomain_loaded( 'wp-tests-domain' ) );
     43                $this->assertFalse( is_textdomain_unloaded( 'wp-tests-domain' ) );
    4344                $this->assertTrue( unload_textdomain( 'wp-tests-domain' ) );
    4445                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
     46                $this->assertTrue( is_textdomain_unloaded( 'wp-tests-domain' ) );
    4547        }
    4648
    4749        /**