Make WordPress Core


Ignore:
Timestamp:
07/18/2025 12:57:14 PM (14 months ago)
Author:
SergeyBiryukov
Message:

I18N: Correct strict comparison in WP_Translations::translate_plural().

This ensures that the $count value is compared as an integer to account for plugins or themes passing a numeric string instead.

Follow-up to [57337].

Props dd32, mukesh27, swissspidy, pmbaldha, SergeyBiryukov.
Fixes #63642.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n/wpTranslations.php

    r57518 r60484  
    227227                load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/l10n/plural-complex.mo' );
    228228
     229                $this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', '1', 'wp-tests-domain' ) ); // 1, 101, 201
    229230                $this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', 101, 'wp-tests-domain' ) ); // 1, 101, 201
    230231                $this->assertSame( '%s razpoložljivi posodobitvi', _n( '%s update available', '%s updates available', 102, 'wp-tests-domain' ) ); // 2, 102, 202
    231232                $this->assertSame( '%s razpoložljive posodobitve', _n( '%s update available', '%s updates available', 103, 'wp-tests-domain' ) ); // 3, 4, 103
    232233                $this->assertSame( '%s razpoložljivih posodobitev', _n( '%s update available', '%s updates available', 5, 'wp-tests-domain' ) ); // 0, 5, 6
     234
     235                // Test with strings that are not in the translation files.
     236                $this->assertSame( 'Singular', _n( 'Singular', 'Plural', 1, 'wp-tests-domain' ) );
     237                $this->assertSame( 'Singular', _n( 'Singular', 'Plural', '1', 'wp-tests-domain' ) );
     238                $this->assertSame( 'Plural', _n( 'Singular', 'Plural', 2, 'wp-tests-domain' ) );
    233239        }
    234240
     
    240246                load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/l10n/plural-complex.php' );
    241247
     248                $this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', '1', 'wp-tests-domain' ) ); // 1, 101, 201
    242249                $this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', 101, 'wp-tests-domain' ) ); // 1, 101, 201
    243250                $this->assertSame( '%s razpoložljivi posodobitvi', _n( '%s update available', '%s updates available', 102, 'wp-tests-domain' ) ); // 2, 102, 202
    244251                $this->assertSame( '%s razpoložljive posodobitve', _n( '%s update available', '%s updates available', 103, 'wp-tests-domain' ) ); // 3, 4, 103
    245252                $this->assertSame( '%s razpoložljivih posodobitev', _n( '%s update available', '%s updates available', 5, 'wp-tests-domain' ) ); // 0, 5, 6
     253
     254                // Test with strings that are not in the translation files.
     255                $this->assertSame( 'Singular', _n( 'Singular', 'Plural', 1, 'wp-tests-domain' ) );
     256                $this->assertSame( 'Singular', _n( 'Singular', 'Plural', '1', 'wp-tests-domain' ) );
     257                $this->assertSame( 'Plural', _n( 'Singular', 'Plural', 2, 'wp-tests-domain' ) );
    246258        }
    247259
Note: See TracChangeset for help on using the changeset viewer.