WP_Translation_File::get_plural_form()publicWP 6.5.0

Returns the plural form for a given number.

Метод класса: WP_Translation_File{}

Хуков нет.

Возвращает

int. Plural form.

Использование

$WP_Translation_File = new WP_Translation_File();
$WP_Translation_File->get_plural_form( $number ): int;
$number(int) (обязательный)
Count.

Список изменений

С версии 6.5.0 Введена.

Код WP_Translation_File::get_plural_form() WP 6.6.2

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