Changeset 57386
- Timestamp:
- 01/30/2024 01:59:46 PM (13 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n/class-wp-translation-file.php
r57344 r57386 204 204 } 205 205 206 return $this->entries[ $text ] ?? false; 206 if ( isset( $this->entries[ $text ] ) ) { 207 return $this->entries[ $text ]; 208 } 209 210 /* 211 * Handle cases where a pluralized string is only used as a singular one. 212 * For example, when both __( 'Product' ) and _n( 'Product', 'Products' ) 213 * are used, the entry key will have the format "ProductNULProducts". 214 * Fall back to looking up just "Product" to support this edge case. 215 */ 216 foreach( $this->entries as $key => $value ) { 217 if ( str_starts_with( $key, $text . "\0" ) ) { 218 $parts = explode( "\0", $value ); 219 return $parts[0]; 220 } 221 } 222 223 return false; 207 224 } 208 225 -
trunk/tests/phpunit/data/l10n/example-simple.php
r57337 r57386 7 7 'plural0' . "\0" . 'plural1' => ['translation0', 'translation1'], 8 8 'contextplural0 with context' . "\0" . 'plural1 with context' => ['translation0 with context', 'translation1 with context'], 9 'Product' . "\0" . 'Products' => 'Produkt' . "\0" . 'Produkte', 9 10 ], 10 11 ]; -
trunk/tests/phpunit/data/l10n/example-simple.po
r57337 r57386 21 21 msgstr[1] "translation1 with context" 22 22 23 23 msgid "Product" 24 msgid_plural "Products" 25 msgstr[0] "Produkt" 26 msgstr[1] "Produkte" -
trunk/tests/phpunit/tests/l10n/wpTranslationsConvert.php
r57350 r57386 174 174 * @covers ::locate_translation 175 175 * @covers ::get_files 176 * @covers WP_Translation_File::translate 176 177 * 177 178 * @dataProvider data_simple_example_files … … 199 200 $this->assertSame( 'translation0 with context', $controller->translate_plural( array( 'plural0 with context', 'plural1 with context' ), 1, 'context', 'unittest' ) ); 200 201 $this->assertSame( 'translation1 with context', $controller->translate_plural( array( 'plural0 with context', 'plural1 with context' ), 2, 'context', 'unittest' ) ); 202 203 $this->assertSame( 'Produkt', $controller->translate( 'Product', '', 'unittest' ) ); 204 $this->assertSame( 'Produkt', $controller->translate_plural( array( 'Product', 'Products' ), 1, '', 'unittest' ) ); 205 $this->assertSame( 'Produkte', $controller->translate_plural( array( 'Product', 'Products' ), 2, '', 'unittest' ) ); 201 206 } 202 207
Note: See TracChangeset
for help on using the changeset viewer.