WP_Translation_File::get_plural_form()publicWP 6.5.0

Returns the plural form for a given number.

Method of the class: WP_Translation_File{}

No Hooks.

Return

Int. Plural form.

Usage

$WP_Translation_File = new WP_Translation_File();
$WP_Translation_File->get_plural_form( $number ): int;
$number(int) (required)
Count.

Changelog

Since 6.5.0 Introduced.

WP_Translation_File::get_plural_form() code WP 6.7.1

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 );
}