Make WordPress Core


Ignore:
Timestamp:
02/01/2024 07:03:55 PM (16 months ago)
Author:
swissspidy
Message:

I18N: Support loading .l10n.php translation files on their own.

Adjusts the translation file lookup in WP_Textdomain_Registry so that just-in-time translation loading
works even if there is only a .l10n.php translation file without a corresponding .mo file.

While language packs continue to contain both file types, this makes it easier to use translations in a project
without having to deal with .mo or .po files.

Props Chrystl.
See #59656.

File:
1 edited

Legend:

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

    r57337 r57516  
    5050
    5151        unload_textdomain( 'internationalized-plugin' );
     52        unload_textdomain( 'internationalized-plugin-2' );
    5253        unload_textdomain( 'internationalized-theme' );
    5354
     
    7980        $actual_output               = i18n_plugin_test();
    8081        $is_textdomain_loaded_after  = is_textdomain_loaded( 'internationalized-plugin' );
     82
     83        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     84
     85        $this->assertFalse( $is_textdomain_loaded_before );
     86        $this->assertSame( 'Das ist ein Dummy Plugin', $actual_output );
     87        $this->assertTrue( $is_textdomain_loaded_after );
     88    }
     89
     90    /**
     91     * @ticket 59656
     92     *
     93     * @covers ::is_textdomain_loaded
     94     */
     95    public function test_plugin_translation_should_be_translated_with_only_an_l10n_php_file() {
     96        add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     97
     98        require_once DIR_TESTDATA . '/plugins/internationalized-plugin-2.php';
     99
     100        $is_textdomain_loaded_before = is_textdomain_loaded( 'internationalized-plugin-2' );
     101        $actual_output               = i18n_plugin_2_test();
     102        $is_textdomain_loaded_after  = is_textdomain_loaded( 'internationalized-plugin-2' );
    81103
    82104        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
Note: See TracChangeset for help on using the changeset viewer.