Make WordPress Core


Ignore:
Timestamp:
12/20/2022 03:10:35 PM (2 years ago)
Author:
swissspidy
Message:

I18N: Change how WP_Textdomain_Registry caches translation information.

WP_Textdomain_Registry was introduced in [53874] and later adjusted in [54682] to store text domains and their language directory paths, addressing issues with just-in-time loading of textdomains when using locale switching and load_*_textdomain() functions.

This change improves how the class stores information about all existing MO files on the site, addressing an issue where translations are not loaded after calling switch_to_locale().

Props johnbillion, ocean90, SergeyBiryukov.
Fixes #57116.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n/wpTextdomainRegistry.php

    r54669 r55010  
    2929        $reflection_property->setAccessible( true );
    3030
    31         $this->assertNull(
     31        $this->assertEmpty(
    3232            $reflection_property->getValue( $this->instance ),
    3333            'Cache not empty by default'
     
    7676            $reflection_property->getValue( $this->instance ),
    7777            'Default plugins path missing from cache'
    78         );
    79     }
    80 
    81     /**
    82      * @covers ::get_path_from_lang_dir
    83      */
    84     public function test_get_does_not_check_themes_directory_for_plugin() {
    85         $reflection          = new ReflectionClass( $this->instance );
    86         $reflection_property = $reflection->getProperty( 'cached_mo_files' );
    87         $reflection_property->setAccessible( true );
    88 
    89         $this->instance->get( 'internationalized-plugin', 'de_DE' );
    90 
    91         $this->assertArrayHasKey(
    92             WP_LANG_DIR . '/plugins',
    93             $reflection_property->getValue( $this->instance ),
    94             'Default plugins path missing from cache'
    95         );
    96         $this->assertArrayNotHasKey(
    97             WP_LANG_DIR . '/themes',
    98             $reflection_property->getValue( $this->instance ),
    99             'Default themes path should not be in cache'
    10078        );
    10179    }
Note: See TracChangeset for help on using the changeset viewer.