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
This commit is contained in:
Pascal Birchler 2024-01-31 21:49:08 +00:00
parent e26bbdbbf7
commit 5e33f4be2d
2 changed files with 1 additions and 22 deletions

View File

@ -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;
}
/**

View File

@ -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' ) );
}
/**