- Timestamp:
- 02/01/2024 08:57:03 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n/class-wp-translation-file.php
r57505 r57518 208 208 209 209 /** 210 * Returns the plural form for a count.210 * Returns the plural form for a given number. 211 211 * 212 212 * @since 6.5.0 … … 220 220 } 221 221 222 // In case a plural form is specified as a header, but no function included, build one.223 222 if ( null === $this->plural_forms && isset( $this->headers['plural-forms'] ) ) { 224 $this->plural_forms = $this->make_plural_form_function( $this->headers['plural-forms'] ); 223 $expression = $this->get_plural_expression_from_header( $this->headers['plural-forms'] ); 224 $this->plural_forms = $this->make_plural_form_function( $expression ); 225 225 } 226 226 … … 232 232 */ 233 233 $result = call_user_func( $this->plural_forms, $number ); 234 234 235 return $result; 235 236 } … … 240 241 241 242 /** 243 * Returns the plural forms expression as a tuple. 244 * 245 * @since 6.5.0 246 * 247 * @param string $header Plural-Forms header string. 248 * @return string Plural forms expression. 249 */ 250 protected function get_plural_expression_from_header( $header ) { 251 if ( preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches ) ) { 252 return trim( $matches[2] ); 253 } 254 255 return 'n != 1'; 256 } 257 258 /** 242 259 * Makes a function, which will return the right translation index, according to the 243 260 * plural forms header. … … 248 265 * @return callable(int $num): int Plural forms function. 249 266 */ 250 p ublicfunction make_plural_form_function( string $expression ): callable {267 protected function make_plural_form_function( string $expression ): callable { 251 268 try { 252 269 $handler = new Plural_Forms( rtrim( $expression, ';' ) );
Note: See TracChangeset
for help on using the changeset viewer.