WP_Translation_File::make_plural_form_function()protectedWP 6.5.0

Makes a function, which will return the right translation index, according to the plural forms header.

Method of the class: WP_Translation_File{}

No Hooks.

Return

callable(Int. $num): int Plural forms function.

Usage

// protected - for code of main (parent) or child class
$result = $this->make_plural_form_function( $expression ): callable;
$expression(string) (required)
Plural form expression.

Changelog

Since 6.5.0 Introduced.

WP_Translation_File::make_plural_form_function() code WP 6.7.1

protected function make_plural_form_function( string $expression ): callable {
	try {
		$handler = new Plural_Forms( rtrim( $expression, ';' ) );
		return array( $handler, 'get' );
	} catch ( Exception $e ) {
		// Fall back to default plural-form function.
		return $this->make_plural_form_function( 'n != 1' );
	}
}