Changeset 57339
- Timestamp:
- 01/23/2024 03:13:32 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/l10n.php (modified) (1 diff)
-
src/wp-includes/l10n/class-wp-translation-controller.php (modified) (3 diffs)
-
tests/phpunit/tests/l10n/wpTranslationController.php (modified) (2 diffs)
-
tests/phpunit/tests/l10n/wpTranslationsConvert.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r57338 r57339 822 822 array_unshift( 823 823 $translation_files, 824 substr_replace( $mofile, ".l10n.$preferred_format", - strlen( $preferred_format) )824 substr_replace( $mofile, ".l10n.$preferred_format", - strlen( '.mo' ) ) 825 825 ); 826 826 } -
trunk/src/wp-includes/l10n/class-wp-translation-controller.php
r57337 r57339 152 152 153 153 if ( null !== $locale ) { 154 foreach ( $this->loaded_translations[ $locale ][ $textdomain ] as $i => $moe ) { 155 if ( $file === $moe || $file === $moe->get_file() ) { 156 unset( $this->loaded_translations[ $locale ][ $textdomain ][ $i ] ); 157 unset( $this->loaded_files[ $moe->get_file() ][ $locale ][ $textdomain ] ); 158 return true; 154 if ( isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) { 155 foreach ( $this->loaded_translations[ $locale ][ $textdomain ] as $i => $moe ) { 156 if ( $file === $moe || $file === $moe->get_file() ) { 157 unset( $this->loaded_translations[ $locale ][ $textdomain ][ $i ] ); 158 unset( $this->loaded_files[ $moe->get_file() ][ $locale ][ $textdomain ] ); 159 return true; 160 } 159 161 } 160 162 } … … 164 166 165 167 foreach ( $this->loaded_translations as $l => $domains ) { 168 if ( ! isset( $domains[ $textdomain ] ) ) { 169 continue; 170 } 171 166 172 foreach ( $domains[ $textdomain ] as $i => $moe ) { 167 173 if ( $file === $moe || $file === $moe->get_file() ) { … … 186 192 */ 187 193 public function unload_textdomain( string $textdomain = 'default', string $locale = null ): bool { 194 $unloaded = false; 195 188 196 if ( null !== $locale ) { 189 foreach ( $this->loaded_translations[ $locale ][ $textdomain ] as $moe ) { 190 unset( $this->loaded_files[ $moe->get_file() ][ $locale ][ $textdomain ] ); 197 if ( isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) { 198 $unloaded = true; 199 foreach ( $this->loaded_translations[ $locale ][ $textdomain ] as $moe ) { 200 unset( $this->loaded_files[ $moe->get_file() ][ $locale ][ $textdomain ] ); 201 } 191 202 } 192 203 193 204 unset( $this->loaded_translations[ $locale ][ $textdomain ] ); 194 205 195 return true; 196 } 197 198 $unloaded = false; 206 return $unloaded; 207 } 199 208 200 209 foreach ( $this->loaded_translations as $l => $domains ) { -
trunk/tests/phpunit/tests/l10n/wpTranslationController.php
r57337 r57339 111 111 * @return void 112 112 */ 113 public function test_load_textdomain_prefers_php_files_by_default() { 114 $load_successful = load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/pomo/simple.mo' ); 115 116 $instance = WP_Translation_Controller::instance(); 117 118 $is_loaded = $instance->is_textdomain_loaded( 'wp-tests-domain', 'en_US' ); 119 120 $unload_mo = $instance->unload_file( DIR_TESTDATA . '/pomo/simple.mo', 'wp-tests-domain' ); 121 $unload_php = $instance->unload_file( DIR_TESTDATA . '/pomo/simple.l10n.php', 'wp-tests-domain' ); 122 123 $unload_successful = unload_textdomain( 'wp-tests-domain' ); 124 125 $this->assertTrue( $load_successful, 'Translation not successfully loaded' ); 126 $this->assertTrue( $is_loaded ); 127 $this->assertFalse( $unload_mo ); 128 $this->assertTrue( $unload_php ); 129 $this->assertTrue( $unload_successful ); 130 } 131 132 /** 133 * @covers ::load_textdomain 134 * 135 * @return void 136 */ 113 137 public function test_load_textdomain_reads_php_files_if_filtered_format_is_unsupported() { 114 138 add_filter( … … 298 322 299 323 /** 324 * @covers ::unload_file 325 * @covers ::unload_textdomain 326 * 327 * @return void 328 */ 329 public function test_unload_non_existent_files_and_textdomains() { 330 $controller = new WP_Translation_Controller(); 331 $this->assertFalse( $controller->unload_textdomain( 'foobarbaz' ) ); 332 $this->assertFalse( $controller->unload_textdomain( 'foobarbaz', 'es_ES' ) ); 333 $this->assertFalse( $controller->unload_textdomain( 'default', 'es_ES' ) ); 334 $this->assertFalse( $controller->unload_file( DIR_TESTDATA . '/l10n/fa_IR.mo' ) ); 335 $this->assertFalse( $controller->unload_file( DIR_TESTDATA . '/l10n/fa_IR.mo', 'es_ES' ) ); 336 } 337 338 /** 300 339 * @covers ::load_textdomain 301 340 * @covers ::unload_textdomain -
trunk/tests/phpunit/tests/l10n/wpTranslationsConvert.php
r57337 r57339 29 29 30 30 /** 31 * @covers ::unload 31 * @covers ::unload_textdomain 32 32 * 33 33 * @return void … … 41 41 /** 42 42 * @covers ::load 43 * @covers ::unload 43 * @covers ::unload_textdomain 44 44 * @covers ::is_textdomain_loaded 45 45 * @covers ::translate … … 63 63 64 64 /** 65 * @covers ::unload 65 * @covers ::unload_file 66 66 * @covers WP_Translation_File::get_file 67 67 * … … 78 78 79 79 /** 80 * @covers ::unload 80 * @covers ::unload_textdomain 81 81 * @covers ::is_textdomain_loaded 82 82 * … … 236 236 /** 237 237 * @covers ::load 238 * @covers ::unload 238 * @covers ::unload_file 239 239 * @covers ::is_textdomain_loaded 240 240 * @covers ::translate … … 290 290 * @covers ::get_locale 291 291 * @covers ::load 292 * @covers ::unload 292 * @covers ::unload_file 293 293 * @covers ::is_textdomain_loaded 294 294 * @covers ::translate … … 334 334 335 335 /** 336 * @covers ::unload 336 * @covers ::unload_textdomain 337 337 * 338 338 * @return void … … 412 412 /** 413 413 * @covers ::load 414 * @covers ::unload415 414 * @covers ::is_textdomain_loaded 416 415 * @covers ::translate
Note: See TracChangeset
for help on using the changeset viewer.