Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/l10n/class-wp-translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function translate_plural( $singular, $plural, $count = 1, $context = ''
}

// Fall back to the original with English grammar rules.
return ( 1 === $count ? $singular : $plural );
return ( 1 === (int) $count ? $singular : $plural );
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/tests/l10n/wpTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,16 @@ public function test_translate_plural() {
public function test_translate_plural_complex() {
load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/l10n/plural-complex.mo' );

$this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', '1', 'wp-tests-domain' ) ); // 1, 101, 201
$this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', 101, 'wp-tests-domain' ) ); // 1, 101, 201
$this->assertSame( '%s razpoložljivi posodobitvi', _n( '%s update available', '%s updates available', 102, 'wp-tests-domain' ) ); // 2, 102, 202
$this->assertSame( '%s razpoložljive posodobitve', _n( '%s update available', '%s updates available', 103, 'wp-tests-domain' ) ); // 3, 4, 103
$this->assertSame( '%s razpoložljivih posodobitev', _n( '%s update available', '%s updates available', 5, 'wp-tests-domain' ) ); // 0, 5, 6

// Test with strings that are not in the translation files.
$this->assertSame( 'Singular', _n( 'Singular', 'Plural', 1, 'wp-tests-domain' ) );
$this->assertSame( 'Singular', _n( 'Singular', 'Plural', '1', 'wp-tests-domain' ) );
$this->assertSame( 'Plural', _n( 'Singular', 'Plural', 2, 'wp-tests-domain' ) );
}

/**
Expand All @@ -239,10 +245,16 @@ public function test_translate_plural_complex() {
public function test_translate_plural_complex_php() {
load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/l10n/plural-complex.php' );

$this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', '1', 'wp-tests-domain' ) ); // 1, 101, 201
$this->assertSame( '%s razpoložljiva posodobitev', _n( '%s update available', '%s updates available', 101, 'wp-tests-domain' ) ); // 1, 101, 201
$this->assertSame( '%s razpoložljivi posodobitvi', _n( '%s update available', '%s updates available', 102, 'wp-tests-domain' ) ); // 2, 102, 202
$this->assertSame( '%s razpoložljive posodobitve', _n( '%s update available', '%s updates available', 103, 'wp-tests-domain' ) ); // 3, 4, 103
$this->assertSame( '%s razpoložljivih posodobitev', _n( '%s update available', '%s updates available', 5, 'wp-tests-domain' ) ); // 0, 5, 6

// Test with strings that are not in the translation files.
$this->assertSame( 'Singular', _n( 'Singular', 'Plural', 1, 'wp-tests-domain' ) );
$this->assertSame( 'Singular', _n( 'Singular', 'Plural', '1', 'wp-tests-domain' ) );
$this->assertSame( 'Plural', _n( 'Singular', 'Plural', 2, 'wp-tests-domain' ) );
}

/**
Expand Down