Make WordPress Core


Ignore:
Timestamp:
02/01/2024 11:43:21 AM (2 years ago)
Author:
swissspidy
Message:

I18N: Improve singular lookup of pluralized strings.

Ensures that string lookup in MO files only uses the singular string.

This matches expected behavior with gettext files and improves compatibility for cases where for example both __( 'Product' ) and _n( 'Product', 'Products’, num ) are used in a project, where both will use the same translation for the singular version. Maintains backward compatibility and feature parity with the pomo library and the PHP translation file format.

Replaces [57386], which was reverted in [57505], with a more accurate and performant solution.

See #59656.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n/class-wp-translations.php

    r57344 r57513  
    9696        }
    9797
    98         // Look for plural original.
    99         $parts           = explode( "\0", $original );
    100         $entry->singular = $parts[0];
    101         if ( isset( $parts[1] ) ) {
    102             $entry->is_plural = true;
    103             $entry->plural    = $parts[1];
    104         }
     98        $entry->singular     = $original;
     99        $entry->translations = explode( "\0", $translations );
     100        $entry->is_plural    = count( $entry->translations ) > 1;
    105101
    106         $entry->translations = explode( "\0", $translations );
    107102        return $entry;
    108103    }
Note: See TracChangeset for help on using the changeset viewer.