WordPress.org

Make WordPress Core

Ticket #34114: 34114.diff

File 34114.diff, 9.4 KB (added by swissspidy, 6 years ago)
  • src/wp-includes/l10n.php

    diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
    index a69a718..4c17411 100644
    function load_child_theme_textdomain( $domain, $path = false ) { 
    793793 */
    794794function get_translations_for_domain( $domain ) {
    795795        global $l10n;
    796         if ( !isset( $l10n[$domain] ) ) {
    797                 $l10n[$domain] = new NOOP_Translations;
     796        if ( ! isset( $l10n[ $domain ] ) &&
     797             ! load_plugin_textdomain( $domain ) &&
     798             ! load_theme_textdomain( $domain )
     799        ) {
     800                $l10n[ $domain ] = new NOOP_Translations;
    798801        }
    799         return $l10n[$domain];
     802        return $l10n[ $domain ];
    800803}
    801804
    802805/**
  • new file tests/phpunit/data/plugins/internationalized-plugin.php

    diff --git tests/phpunit/data/plugins/internationalized-plugin.php tests/phpunit/data/plugins/internationalized-plugin.php
    new file mode 100644
    index 0000000..4b56846
    - +  
     1<?php
     2/*
     3Plugin Name: Dummy Plugin
     4Plugin URI: https://wordpress.org/
     5Description: For testing purposes only.
     6Version: 1.0.0
     7Text Domain: internationalized-plugin
     8*/
     9
     10function i18n_plugin_test() {
     11        return __( 'This is a dummy plugin', 'internationalized-plugin' );
     12}
  • new file tests/phpunit/data/pomo/internationalized-plugin-de_DE.po

    diff --git tests/phpunit/data/pomo/internationalized-plugin-de_DE.mo tests/phpunit/data/pomo/internationalized-plugin-de_DE.mo
    new file mode 100644
    index 0000000..359823e
    Binary files /dev/null and tests/phpunit/data/pomo/internationalized-plugin-de_DE.mo differ
    diff --git tests/phpunit/data/pomo/internationalized-plugin-de_DE.po tests/phpunit/data/pomo/internationalized-plugin-de_DE.po
    new file mode 100644
    index 0000000..c31dad0
    - +  
     1msgid ""
     2msgstr ""
     3"Project-Id-Version: \n"
     4"POT-Creation-Date: 2015-12-31 16:31+0100\n"
     5"PO-Revision-Date: 2015-12-31 17:55+0100\n"
     6"Last-Translator: Pascal Birchler <swissspidy@wordpress.org>\n"
     7"Language-Team: \n"
     8"Language: de_DE\n"
     9"MIME-Version: 1.0\n"
     10"Content-Type: text/plain; charset=UTF-8\n"
     11"Content-Transfer-Encoding: 8bit\n"
     12"X-Generator: Poedit 1.8.4\n"
     13"X-Poedit-Basepath: .\n"
     14"Plural-Forms: nplurals=2; plural=(n != 1);\n"
     15"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;"
     16"_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;"
     17"esc_html_x:1,2c\n"
     18"X-Textdomain-Support: yes\n"
     19"X-Poedit-SearchPath-0: .\n"
     20
     21#: internationalized-plugin.php:11
     22msgid "This is a dummy plugin"
     23msgstr "Das ist ein Dummy Plugin"
  • new file tests/phpunit/data/pomo/internationalized-theme-de_DE.po

    diff --git tests/phpunit/data/pomo/internationalized-theme-de_DE.mo tests/phpunit/data/pomo/internationalized-theme-de_DE.mo
    new file mode 100644
    index 0000000..16244ee
    Binary files /dev/null and tests/phpunit/data/pomo/internationalized-theme-de_DE.mo differ
    diff --git tests/phpunit/data/pomo/internationalized-theme-de_DE.po tests/phpunit/data/pomo/internationalized-theme-de_DE.po
    new file mode 100644
    index 0000000..f658b9e
    - +  
     1msgid ""
     2msgstr ""
     3"Project-Id-Version: \n"
     4"POT-Creation-Date: 2015-12-31 16:38+0100\n"
     5"PO-Revision-Date: 2015-12-31 16:38+0100\n"
     6"Last-Translator: Pascal Birchler <swissspidy@wordpress.org>\n"
     7"Language-Team: \n"
     8"Language: de_DE\n"
     9"MIME-Version: 1.0\n"
     10"Content-Type: text/plain; charset=UTF-8\n"
     11"Content-Transfer-Encoding: 8bit\n"
     12"X-Generator: Poedit 1.8.4\n"
     13"X-Poedit-Basepath: .\n"
     14"Plural-Forms: nplurals=2; plural=(n != 1);\n"
     15"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;"
     16"_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;"
     17"esc_html_x:1,2c\n"
     18"X-Textdomain-Support: yes\n"
     19"X-Poedit-SearchPath-0: .\n"
     20
     21#: functions.php:7
     22msgid "This is a dummy theme"
     23msgstr "Das ist ein Dummy Theme"
  • new file tests/phpunit/data/themedir1/internationalized-theme/functions.php

    diff --git tests/phpunit/data/themedir1/internationalized-theme/functions.php tests/phpunit/data/themedir1/internationalized-theme/functions.php
    new file mode 100644
    index 0000000..d836c4b
    - +  
     1<?php
     2/**
     3 * Dummy theme.
     4 */
     5
     6function i18n_theme_test() {
     7        return __( 'This is a dummy theme', 'internationalized-theme' );
     8}
  • new file tests/phpunit/data/themedir1/internationalized-theme/index.php

    diff --git tests/phpunit/data/themedir1/internationalized-theme/index.php tests/phpunit/data/themedir1/internationalized-theme/index.php
    new file mode 100644
    index 0000000..c674182
    - +  
     1<?php
     2/**
     3 * Dummy theme.
     4 */
  • new file tests/phpunit/data/themedir1/internationalized-theme/style.css

    diff --git tests/phpunit/data/themedir1/internationalized-theme/style.css tests/phpunit/data/themedir1/internationalized-theme/style.css
    new file mode 100644
    index 0000000..ea472af
    - +  
     1/*
     2Theme Name: Internationalized Theme
     3Theme URI: https://wordpress.org/
     4Description: For testing purposes only.
     5Version: 1.0.0
     6Text Domain: internationalized-theme
     7*/
  • tests/phpunit/tests/l10n.php

    diff --git tests/phpunit/tests/l10n.php tests/phpunit/tests/l10n.php
    index 62357f0..84737f3 100644
     
    55 * @group i18n
    66 */
    77class Tests_L10n extends WP_UnitTestCase {
    8 
    98        function test_load_unload_textdomain() {
    109                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
    1110                $this->assertFalse( unload_textdomain( 'wp-tests-domain' ) );
    class Tests_L10n extends WP_UnitTestCase { 
    1716                $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) );
    1817        }
    1918
     19        public function _set_locale_to_german() {
     20                return 'de_DE';
     21        }
     22
     23        /**
     24         * @ticket 34114
     25         */
     26        public function test_load_plugin_textdomain_just_in_time() {
     27                add_filter( 'locale', array( $this, '_set_locale_to_german' ) );
     28
     29                $this->_copy_file( DIR_TESTDATA . '/pomo/internationalized-plugin-de_DE.mo', WP_CONTENT_DIR . '/languages/plugins' );
     30                $this->_copy_file( DIR_TESTDATA . '/pomo/internationalized-plugin-de_DE.po', WP_CONTENT_DIR . '/languages/plugins' );
     31                $this->_copy_file( DIR_TESTDATA . '/plugins/internationalized-plugin.php', WP_CONTENT_DIR . '/plugins' );
     32
     33                activate_plugin( 'internationalized-plugin.php' );
     34                $this->assertTrue( is_plugin_active( 'internationalized-plugin.php' ) );
     35                $this->assertFalse( is_textdomain_loaded( 'internationalized-plugin' ) );
     36
     37                $this->assertTrue( function_exists( 'i18n_plugin_test' ) );
     38
     39                $this->assertSame( 'Das ist ein Dummy Plugin', i18n_plugin_test() );
     40                $this->assertTrue( is_textdomain_loaded( 'internationalized-plugin' ) );
     41
     42                remove_filter( 'locale', array( $this, '_set_locale_to_german' ) );
     43        }
     44
     45        /**
     46         * @ticket 34114
     47         */
     48        public function test_load_theme_textdomain_just_in_time() {
     49                add_filter( 'locale', array( $this, '_set_locale_to_german' ) );
     50
     51                $this->_copy_file( DIR_TESTDATA . '/pomo/internationalized-theme-de_DE.mo', WP_CONTENT_DIR . '/languages/themes' );
     52                $this->_copy_file( DIR_TESTDATA . '/pomo/internationalized-theme-de_DE.po', WP_CONTENT_DIR . '/languages/themes' );
     53                $this->_copy_file( DIR_TESTDATA . '/themedir1/internationalized-theme', WP_CONTENT_DIR . '/themes/internationalized-theme' );
     54
     55                switch_theme( 'internationalized-theme' );
     56                $this->assertSame( 'Internationalized Theme', wp_get_theme()->get( 'Name' ) );
     57                $this->assertFalse( is_textdomain_loaded( 'internationalized-theme' ) );
     58                $this->assertTrue( validate_current_theme() );
     59
     60                include_once( get_stylesheet_directory() . '/functions.php' );
     61
     62                $this->assertTrue( function_exists( 'i18n_theme_test' ) );
     63
     64                $this->assertSame( 'Das ist ein Dummy Theme', i18n_theme_test() );
     65                $this->assertTrue( is_textdomain_loaded( 'internationalized-theme' ) );
     66
     67                remove_filter( 'locale', array( $this, '_set_locale_to_german' ) );
     68        }
     69
    2070        /**
    2171         * @ticket 35073
    2272         */
    class Tests_L10n extends WP_UnitTestCase { 
    2676                $this->assertEquals( 'first-before-bar|second-before-bar', before_last_bar( 'first-before-bar|second-before-bar|after-last-bar' ) );
    2777        }
    2878
     79        /**
     80         * Copy file or directory from one place to another.
     81         *
     82         * @access private
     83         *
     84         * @param string $source
     85         * @param string $destination
     86         */
     87        private function _copy_file( $source, $destination ) {
     88                if ( ! is_dir( $destination ) ) {
     89                        mkdir( $destination, 0777, true );
     90                }
     91
     92                if ( is_dir( $source ) ) {
     93                        $files_to_move = array();
     94                        if ( $source_dir = opendir( $source ) ) {
     95                                while ( false !== $file = readdir( $source_dir ) ) {
     96                                        if ( 0 !== strpos( $file, '.' ) ) {
     97                                                $files_to_move[] = $file;
     98                                        }
     99                                }
     100                        }
     101
     102                        @closedir( $source_dir );
     103
     104                        foreach ( $files_to_move as $file_to_move ) {
     105                                unlink( $destination . '/' . $file_to_move );
     106                                copy( $source . '/' . $file_to_move, $destination . '/' . $file_to_move );
     107                                chmod( $destination . '/' . $file_to_move, 0777 );
     108                        }
     109                } else {
     110                        unlink( $destination . '/' . basename( $source ) );
     111                        copy( $source, $destination . '/' . basename( $source ) );
     112                        chmod( $destination . '/' . basename( $source ), 0777 );
     113                }
     114        }
     115
    29116}
  • tests/phpunit/tests/theme/themeDir.php

    diff --git tests/phpunit/tests/theme/themeDir.php tests/phpunit/tests/theme/themeDir.php
    index d5060f8..a6df7ba 100644
    class Tests_Theme_ThemeDir extends WP_UnitTestCase { 
    159159                        'My Subdir Theme',// theme in a subdirectory should work
    160160                        'Page Template Theme', // theme with page templates for other test code
    161161                        'Theme with Spaces in the Directory',
     162                        'Internationalized Theme',
    162163                );
    163164
    164165                sort($theme_names);