WordPress.org

Make WordPress Core

Ticket #37819: 37819.2.diff

File 37819.2.diff, 12.4 KB (added by imath, 3 years ago)
  • src/wp-includes/l10n.php

    diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
    index aaa7611..e6e3904 100644
    function load_textdomain( $domain, $mofile ) { 
    557557        if ( !$mo->import_from_file( $mofile ) ) return false;
    558558
    559559        if ( isset( $l10n[$domain] ) )
    560                 $mo->merge_with( $l10n[$domain] );
     560                $mo->merge_originals_with( $l10n[$domain] );
    561561
    562562        unset( $l10n_unloaded[ $domain ] );
    563563
    564         $l10n[$domain] = &$mo;
     564        $l10n[$domain] = $mo;
    565565
    566566        return true;
    567567}
    function is_rtl() { 
    11481148                return false;
    11491149        }
    11501150        return $wp_locale->is_rtl();
    1151 }
    1152  No newline at end of file
     1151}
  • tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.po

    diff --git tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.mo tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.mo
    index e69de29..730ab99 100644
    Binary files tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.mo and tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.mo differ
    diff --git tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.po tests/phpunit/data/languages/internationalized-plugin/internationalized-plugin-fr_FR.po
    index e69de29..7aa7d89 100644
     
     1msgid ""
     2msgstr ""
     3"Project-Id-Version: internationalized plugin\n"
     4"POT-Creation-Date: 2016-09-19 07:36+0100\n"
     5"PO-Revision-Date: 2016-09-22 11:01+0100\n"
     6"Last-Translator: imath <mathchristo@yahoo.fr>\n"
     7"Language-Team: \n"
     8"Language: fr_FR\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.5.7\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 "Ceci est un plugin factice"
  • tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.po

    diff --git tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.mo tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.mo
    index e69de29..ece00bd 100644
    Binary files tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.mo and tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.mo differ
    diff --git tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.po tests/phpunit/data/languages/plugins/internationalized-plugin-fr_FR.po
    index e69de29..abce25d 100644
     
     1msgid ""
     2msgstr ""
     3"Project-Id-Version: internationalized plugin\n"
     4"POT-Creation-Date: 2016-09-19 07:36+0100\n"
     5"PO-Revision-Date: 2016-09-22 11:19+0100\n"
     6"Last-Translator: imath <mathchristo@yahoo.fr>\n"
     7"Language-Team: \n"
     8"Language: fr_FR\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.5.7\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 "Ceci est un dummy plugin"
     24
     25#: internationalized-plugin.php:15
     26msgid "This is another string"
     27msgstr "Ceci est une autre chaine de caractères"
     28
     29#: internationalized-plugin.php:19
     30msgid "This is a third string"
     31msgstr "Ceci est une troisième chaine de caractères"
  • tests/phpunit/data/plugins/internationalized-plugin.php

    diff --git tests/phpunit/data/plugins/internationalized-plugin.php tests/phpunit/data/plugins/internationalized-plugin.php
    index 4b56846..5188869 100644
    Text Domain: internationalized-plugin 
    1010function i18n_plugin_test() {
    1111        return __( 'This is a dummy plugin', 'internationalized-plugin' );
    1212}
     13
     14function i18n_plugin_test_2() {
     15        return __( 'This is another string', 'internationalized-plugin' );
     16}
     17
     18function i18n_plugin_test_3() {
     19        return __( 'This is a third string', 'internationalized-plugin' );
     20}
  • tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.po

    diff --git tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.mo tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.mo
    index e69de29..2240875 100644
    Binary files tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.mo and tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.mo differ
    diff --git tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.po tests/phpunit/data/plugins/internationalized-plugin/internationalized-plugin-fr_FR.po
    index e69de29..e757a97 100644
     
     1msgid ""
     2msgstr ""
     3"Project-Id-Version: internationalized plugin\n"
     4"POT-Creation-Date: 2016-09-19 07:36+0100\n"
     5"PO-Revision-Date: 2016-09-22 11:23+0100\n"
     6"Last-Translator: imath <mathchristo@yahoo.fr>\n"
     7"Language-Team: \n"
     8"Language: fr_FR\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.5.7\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 "Ceci est un dummy plugin"
     24
     25#: internationalized-plugin.php:15
     26msgid "This is another string"
     27msgstr "Ceci est une autre chaine de caractères"
     28
     29#: internationalized-plugin.php:19
     30msgid "This is a third string"
     31msgstr "Ceci est la chaine de caractères numéro trois"
  • tests/phpunit/tests/l10n/loadTextdomainJustInTime.php

    diff --git tests/phpunit/tests/l10n/loadTextdomainJustInTime.php tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
    index f73cfd5..719fea1 100644
    class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 
    4848                return 'de_DE';
    4949        }
    5050
     51        public function filter_set_locale_to_french() {
     52                return 'fr_FR';
     53        }
     54
    5155        /**
    5256         * @ticket 34114
    5357         */
    class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 
    141145                $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_final );
    142146                $this->assertTrue( $is_textdomain_loaded_final );
    143147        }
     148
     149        /**
     150         * @ticket 37819
     151         */
     152        public function test_should_allow_custom_text_domain() {
     153                add_filter( 'locale', array( $this, 'filter_set_locale_to_french' ) );
     154
     155                require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     156
     157                $this->assertSame( 'Ceci est un dummy plugin', i18n_plugin_test() );
     158
     159                $this->assertSame( 'Ceci est une autre chaine de caractères', i18n_plugin_test_2() );
     160
     161                load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/internationalized-plugin/internationalized-plugin-fr_FR.mo' );
     162
     163                $this->assertSame( 'Ceci est un plugin factice', i18n_plugin_test() );
     164
     165                $this->assertSame( 'Ceci est une autre chaine de caractères', i18n_plugin_test_2() );
     166
     167                // Reset for next tests
     168                unload_textdomain( 'internationalized-plugin' );
     169
     170                remove_filter( 'locale', array( $this, 'filter_set_locale_to_french' ) );
     171        }
     172
     173        /**
     174         * @ticket 37819
     175         */
     176        public function test_should_allow_multiple_custom_text_domain_full_entries_first() {
     177                add_filter( 'locale', array( $this, 'filter_set_locale_to_french' ) );
     178
     179                $expected = array(
     180                        'wp-lang-dir' => array(
     181                                'Ceci est un dummy plugin',
     182                                'Ceci est une autre chaine de caractères',
     183                                'Ceci est une troisième chaine de caractères',
     184                        ),
     185                        'custom-dir-1' => array(
     186                                'Ceci est un dummy plugin',
     187                                'Ceci est une autre chaine de caractères',
     188                                'Ceci est la chaine de caractères numéro trois', // Should be added by DIR_TESTDATA . '/plugins/*'
     189                        ),
     190                        'custom-dir-2' => array(
     191                                'Ceci est un plugin factice',                    // Should be added by WP_LANG_DIR . '/internationalized-plugin/*'
     192                                'Ceci est une autre chaine de caractères',       // Should be kept from WP_LANG_DIR/plugins/' (as this entry is missing in WP_LANG_DIR . '/internationalized-plugin/*' )
     193                                'Ceci est la chaine de caractères numéro trois', // Should be kept from DIR_TESTDATA . '/plugins/*' (as this entry is missing in WP_LANG_DIR . '/internationalized-plugin/*' )
     194                        ),
     195                );
     196
     197                // Check WP_LANG_DIR/plugins/*.mo is loaded "just in time"
     198                $this->assertSame( $expected['wp-lang-dir'], array( i18n_plugin_test(), i18n_plugin_test_2(), i18n_plugin_test_3() ) );
     199
     200                require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     201
     202                // Check overriding with a custom file containing all entries is ok
     203                load_textdomain( 'internationalized-plugin', DIR_TESTDATA . '/plugins/internationalized-plugin/internationalized-plugin-fr_FR.mo' );
     204
     205                $this->assertSame( $expected['custom-dir-1'], array( i18n_plugin_test(), i18n_plugin_test_2(), i18n_plugin_test_3() ) );
     206
     207                // Check overriding with a custom file containing incomplete entries is ok
     208                load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/internationalized-plugin/internationalized-plugin-fr_FR.mo' );
     209
     210                $this->assertSame( $expected['custom-dir-2'], array( i18n_plugin_test(), i18n_plugin_test_2(), i18n_plugin_test_3() ) );
     211
     212                // Reset for next tests
     213                unload_textdomain( 'internationalized-plugin' );
     214
     215                remove_filter( 'locale', array( $this, 'filter_set_locale_to_french' ) );
     216        }
     217
     218        /**
     219         * @ticket 37819
     220         */
     221        public function test_should_allow_multiple_custom_text_domain_incomplete_entries_first() {
     222                add_filter( 'locale', array( $this, 'filter_set_locale_to_french' ) );
     223
     224                $expected = array(
     225                        'wp-lang-dir' => array(
     226                                'Ceci est un dummy plugin',
     227                                'Ceci est une autre chaine de caractères',
     228                                'Ceci est une troisième chaine de caractères',
     229                        ),
     230                        'custom-dir-1' => array(
     231                                'Ceci est un plugin factice',                   // Should be added by WP_LANG_DIR . '/internationalized-plugi/*'
     232                                'Ceci est une autre chaine de caractères',      // Should be kept from WP_LANG_DIR/plugins/' (as this entry is missing in WP_LANG_DIR . '/internationalized-plugin/*' )
     233                                'Ceci est une troisième chaine de caractères',  // Should be kept from WP_LANG_DIR/plugins/' (as this entry is missing in WP_LANG_DIR . '/internationalized-plugin/*' )
     234                        ),
     235                        'custom-dir-2' => array(
     236                                'Ceci est un dummy plugin',                      // Should be added by DIR_TESTDATA . '/plugins/*'
     237                                'Ceci est une autre chaine de caractères',       // Shouldn't change as entries are the same
     238                                'Ceci est la chaine de caractères numéro trois', // Should be added by DIR_TESTDATA . '/plugins/*'
     239                        ),
     240                );
     241
     242                // Check WP_LANG_DIR/plugins/*.mo is loaded "just in time"
     243                $this->assertSame( $expected['wp-lang-dir'], array( i18n_plugin_test(), i18n_plugin_test_2(), i18n_plugin_test_3() ) );
     244
     245                require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     246
     247                // Check overriding with a custom file containing incomplete entries is ok
     248                load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/internationalized-plugin/internationalized-plugin-fr_FR.mo' );
     249
     250                $this->assertSame( $expected['custom-dir-1'], array( i18n_plugin_test(), i18n_plugin_test_2(), i18n_plugin_test_3() ) );
     251
     252                // Check overriding with a custom file containing full entries is ok
     253                load_textdomain( 'internationalized-plugin', DIR_TESTDATA . '/plugins/internationalized-plugin/internationalized-plugin-fr_FR.mo' );
     254
     255                $this->assertSame( $expected['custom-dir-2'], array( i18n_plugin_test(), i18n_plugin_test_2(), i18n_plugin_test_3() ) );
     256
     257                // Reset for next tests
     258                unload_textdomain( 'internationalized-plugin' );
     259
     260                remove_filter( 'locale', array( $this, 'filter_set_locale_to_french' ) );
     261        }
    144262}