Make WordPress Core


Ignore:
Timestamp:
11/20/2024 01:32:57 PM (3 months ago)
Author:
desrosj
Message:

i18n: Account for load_*_textdomain() after JIT loading.

When load_*_textdomain() functions are called after WordPress has already attempted just-in-time loading of translations, nothing happens.

This updates the related logic to retry translation loading when a custom path is set to ensure all translations are available.

Additionally, this also fixes cases where an en_US.mo file is provided with non-English strings to override the default language.

Follow up to [59157].

Reviewed by SergeyBiryukov.
Merges [59430] to the 6.7 branch.

Props swissspidy, peterwilsoncc, desrosj, apermo, sergeybiryukov, wildworks, tigriweb, twvania, looswebstudio, stimul, audrasjb, finntown, bluantinoo, timwhitlock, albigdd.
See #62337.

Location:
branches/6.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.7

  • branches/6.7/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php

    r57516 r59433  
    343343        $this->assertSame( 1, $filter->get_call_count() );
    344344    }
     345
     346    /**
     347     * @ticket 44937
     348     * @ticket 62337
     349     *
     350     * @covers ::load_plugin_textdomain
     351     * @covers ::is_textdomain_loaded
     352     * @covers WP_Textdomain_Registry::set_custom_path
     353     */
     354    public function test_plugin_translation_should_be_translated_when_calling_load_plugin_textdomain_too_late() {
     355        require_once DIR_TESTDATA . '/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php';
     356
     357        add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     358
     359        $is_textdomain_loaded_before = is_textdomain_loaded( 'custom-internationalized-plugin' );
     360        $output_before               = custom_i18n_plugin_test();
     361
     362        $is_textdomain_loaded_middle = is_textdomain_loaded( 'custom-internationalized-plugin' );
     363
     364        custom_i18n_load_textdomain();
     365
     366        $output_after               = custom_i18n_plugin_test();
     367        $is_textdomain_loaded_after = is_textdomain_loaded( 'custom-internationalized-plugin' );
     368
     369        $this->assertFalse( $is_textdomain_loaded_before );
     370        $this->assertFalse( $is_textdomain_loaded_middle );
     371        $this->assertSame( 'This is a dummy plugin', $output_before );
     372        $this->assertSame( 'Das ist ein Dummy Plugin', $output_after );
     373        $this->assertTrue( $is_textdomain_loaded_after );
     374    }
    345375}
Note: See TracChangeset for help on using the changeset viewer.