WP_Translation_File::get_plural_form( int $number ): int

In this article

Returns the plural form for a given number.

Parameters

$numberintrequired
Count.

Return

int Plural form.

Source

public function get_plural_form( int $number ): int {
	if ( ! $this->parsed ) {
		$this->parse_file();
	}

	if ( null === $this->plural_forms && isset( $this->headers['plural-forms'] ) ) {
		$expression         = $this->get_plural_expression_from_header( $this->headers['plural-forms'] );
		$this->plural_forms = $this->make_plural_form_function( $expression );
	}

	if ( is_callable( $this->plural_forms ) ) {
		/**
		 * Plural form.
		 *
		 * @var int $result Plural form.
		 */
		$result = call_user_func( $this->plural_forms, $number );

		return $result;
	}

	// Default plural form matches English, only "One" is considered singular.
	return ( 1 === $number ? 0 : 1 );
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.