From 5e33f4be2d723205e259aeaf1d451058da96cffb Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 31 Jan 2024 21:49:08 +0000 Subject: [PATCH] I18N: Revert [57386] pending further investigation. Reverts the change for fallback string lookup due to a performance regression in the bad case scenario. See #59656. git-svn-id: https://develop.svn.wordpress.org/trunk@57505 602fd350-edb4-49c9-b593-d223f7449a82 --- .../l10n/class-wp-translation-file.php | 19 +------------------ .../tests/l10n/wpTranslationsConvert.php | 4 ---- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/wp-includes/l10n/class-wp-translation-file.php b/src/wp-includes/l10n/class-wp-translation-file.php index 8e7bfba1b1..93842bec10 100644 --- a/src/wp-includes/l10n/class-wp-translation-file.php +++ b/src/wp-includes/l10n/class-wp-translation-file.php @@ -203,24 +203,7 @@ abstract class WP_Translation_File { $this->parse_file(); } - if ( isset( $this->entries[ $text ] ) ) { - return $this->entries[ $text ]; - } - - /* - * Handle cases where a pluralized string is only used as a singular one. - * For example, when both __( 'Product' ) and _n( 'Product', 'Products' ) - * are used, the entry key will have the format "ProductNULProducts". - * Fall back to looking up just "Product" to support this edge case. - */ - foreach ( $this->entries as $key => $value ) { - if ( str_starts_with( $key, $text . "\0" ) ) { - $parts = explode( "\0", $value ); - return $parts[0]; - } - } - - return false; + return $this->entries[ $text ] ?? false; } /** diff --git a/tests/phpunit/tests/l10n/wpTranslationsConvert.php b/tests/phpunit/tests/l10n/wpTranslationsConvert.php index ea318eb329..000388aabb 100644 --- a/tests/phpunit/tests/l10n/wpTranslationsConvert.php +++ b/tests/phpunit/tests/l10n/wpTranslationsConvert.php @@ -199,10 +199,6 @@ class WP_Translation_Controller_Convert_Tests extends WP_UnitTestCase { $this->assertSame( 'translation1 with context', $controller->translate_plural( array( 'plural0 with context', 'plural1 with context' ), 0, 'context', 'unittest' ) ); $this->assertSame( 'translation0 with context', $controller->translate_plural( array( 'plural0 with context', 'plural1 with context' ), 1, 'context', 'unittest' ) ); $this->assertSame( 'translation1 with context', $controller->translate_plural( array( 'plural0 with context', 'plural1 with context' ), 2, 'context', 'unittest' ) ); - - $this->assertSame( 'Produkt', $controller->translate( 'Product', '', 'unittest' ) ); - $this->assertSame( 'Produkt', $controller->translate_plural( array( 'Product', 'Products' ), 1, '', 'unittest' ) ); - $this->assertSame( 'Produkte', $controller->translate_plural( array( 'Product', 'Products' ), 2, '', 'unittest' ) ); } /**