Ticket #37113: 37113.3.diff
File 37113.3.diff, 5.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/l10n.php
509 509 * 510 510 * @since 1.5.0 511 511 * 512 * @global array $l10n 512 * @global array $l10n An array of all currently loaded text domains. 513 * @global array $l10n_unloaded An array of all text domains that have been unloaded again. 513 514 * 514 515 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 515 516 * @param string $mofile Path to the .mo file. 516 517 * @return bool True on success, false on failure. 517 518 */ 518 519 function load_textdomain( $domain, $mofile ) { 519 global $l10n ;520 global $l10n, $l10n_unloaded; 520 521 522 $l10n_unloaded = (array) $l10n_unloaded; 523 521 524 /** 522 525 * Filters whether to override the .mo file loading. 523 526 * … … 530 533 $plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile ); 531 534 532 535 if ( true == $plugin_override ) { 536 unset( $l10n_unloaded[ $domain ] ); 537 533 538 return true; 534 539 } 535 540 … … 561 566 if ( isset( $l10n[$domain] ) ) 562 567 $mo->merge_with( $l10n[$domain] ); 563 568 569 unset( $l10n_unloaded[ $domain ] ); 570 564 571 $l10n[$domain] = &$mo; 565 572 566 573 return true; … … 571 578 * 572 579 * @since 3.0.0 573 580 * 574 * @global array $l10n 581 * @global array $l10n An array of all currently loaded text domains. 582 * @global array $l10n_unloaded An array of all text domains that have been unloaded again. 575 583 * 576 584 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 577 585 * @return bool Whether textdomain was unloaded. 578 586 */ 579 587 function unload_textdomain( $domain ) { 580 global $l10n ;588 global $l10n, $l10n_unloaded; 581 589 590 $l10n_unloaded = (array) $l10n_unloaded; 591 582 592 /** 583 593 * Filters whether to override the text domain unloading. 584 594 * … … 589 599 */ 590 600 $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain ); 591 601 592 if ( $plugin_override ) 602 if ( $plugin_override ) { 603 $l10n_unloaded[ $domain ] = true; 604 593 605 return true; 606 } 594 607 595 608 /** 596 609 * Fires before the text domain is unloaded. … … 603 616 604 617 if ( isset( $l10n[$domain] ) ) { 605 618 unset( $l10n[$domain] ); 619 620 $l10n_unloaded[ $domain ] = true; 621 606 622 return true; 607 623 } 608 624 … … 793 809 * @access private 794 810 * 795 811 * @see get_translations_for_domain() 812 * @global array $l10n_unloaded An array of all text domains that have been unloaded again. 796 813 * 797 814 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 798 815 * @return bool True when the textdomain is successfully loaded, false otherwise. 799 816 */ 800 817 function _load_textdomain_just_in_time( $domain ) { 818 global $l10n_unloaded; 819 820 $l10n_unloaded = (array) $l10n_unloaded; 821 801 822 static $cached_mofiles = null; 802 823 803 824 // Short-circuit if domain is 'default' which is reserved for core. 804 if ( 'default' === $domain ) {825 if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) { 805 826 return false; 806 827 } 807 828 -
tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
89 89 } 90 90 91 91 /** 92 * @ticket 34114 292 * @ticket 34114 93 93 */ 94 94 public function test_get_translations_for_domain_does_not_return_null_if_override_load_textdomain_is_used() { 95 95 add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); … … 100 100 101 101 $this->assertTrue( $translations instanceof NOOP_Translations ); 102 102 } 103 104 /** 105 * @ticket 37113 106 */ 107 public function test_should_allow_unloading_of_text_domain() { 108 add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 109 110 require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; 111 112 $expected_output_before = i18n_plugin_test(); 113 $is_textdomain_loaded_before = is_textdomain_loaded( 'internationalized-plugin' ); 114 115 unload_textdomain( 'internationalized-plugin' ); 116 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 117 118 $expected_output_after = i18n_plugin_test(); 119 $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin' ); 120 121 add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 122 load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' ); 123 124 $expected_output_final = i18n_plugin_test(); 125 $is_textdomain_loaded_final = is_textdomain_loaded( 'internationalized-plugin' ); 126 127 unload_textdomain( 'internationalized-plugin' ); 128 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 129 130 // Text domain loaded just in time. 131 $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_before ); 132 $this->assertTrue( $is_textdomain_loaded_before ); 133 134 // Text domain unloaded. 135 $this->assertSame( 'This is a dummy plugin', $expected_output_after ); 136 $this->assertFalse( $is_textdomain_loaded_after ); 137 138 // Text domain loaded manually again. 139 $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_final ); 140 $this->assertTrue( $is_textdomain_loaded_final ); 141 } 103 142 }