diff --git a/wp-includes/l10n/class-wp-translation-file.php b/wp-includes/l10n/class-wp-translation-file.php index 93842bec10..e6dbdb85be 100644 --- a/wp-includes/l10n/class-wp-translation-file.php +++ b/wp-includes/l10n/class-wp-translation-file.php @@ -207,7 +207,7 @@ abstract class WP_Translation_File { } /** - * Returns the plural form for a count. + * Returns the plural form for a given number. * * @since 6.5.0 * @@ -219,9 +219,9 @@ abstract class WP_Translation_File { $this->parse_file(); } - // In case a plural form is specified as a header, but no function included, build one. if ( null === $this->plural_forms && isset( $this->headers['plural-forms'] ) ) { - $this->plural_forms = $this->make_plural_form_function( $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 ) ) { @@ -231,6 +231,7 @@ abstract class WP_Translation_File { * @var int $result Plural form. */ $result = call_user_func( $this->plural_forms, $number ); + return $result; } @@ -238,6 +239,22 @@ abstract class WP_Translation_File { return ( 1 === $number ? 0 : 1 ); } + /** + * Returns the plural forms expression as a tuple. + * + * @since 6.5.0 + * + * @param string $header Plural-Forms header string. + * @return string Plural forms expression. + */ + protected function get_plural_expression_from_header( $header ) { + if ( preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches ) ) { + return trim( $matches[2] ); + } + + return 'n != 1'; + } + /** * Makes a function, which will return the right translation index, according to the * plural forms header. @@ -247,7 +264,7 @@ abstract class WP_Translation_File { * @param string $expression Plural form expression. * @return callable(int $num): int Plural forms function. */ - public function make_plural_form_function( string $expression ): callable { + protected function make_plural_form_function( string $expression ): callable { try { $handler = new Plural_Forms( rtrim( $expression, ';' ) ); return array( $handler, 'get' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index b3a409ecf6..e78f96755c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57517'; +$wp_version = '6.5-alpha-57518'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.