wppaste
WordPress

Gettext_Translations

Since
2.8.0
Source
wp-includes/pomo/translations.php:254
Gettext_Translations class.

Compatibility

WordPress
since 2.8.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 2

$_npluralsintpublic
Number of plural forms.
$_gettext_select_plural_formcallablepublic
Callback to retrieve the plural form.

Methods · 6

Source code

	class Gettext_Translations extends Translations { 		/**		 * Number of plural forms.		 *		 * @var int		 *		 * @since 2.8.0		 */		public $_nplurals; 		/**		 * Callback to retrieve the plural form.		 *		 * @var callable		 *		 * @since 2.8.0		 */		public $_gettext_select_plural_form; 		/**		 * The gettext implementation of select_plural_form.		 *		 * It lives in this class, because there are more than one descendant, which will use it and		 * they can't share it effectively.		 *		 * @since 2.8.0		 *		 * @param int $count Plural forms count.		 * @return int Plural form to use.		 */		public function gettext_select_plural_form( $count ) {			if ( ! isset( $this->_gettext_select_plural_form ) || is_null( $this->_gettext_select_plural_form ) ) {				list( $nplurals, $expression )     = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) );				$this->_nplurals                   = $nplurals;				$this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression );			}			return call_user_func( $this->_gettext_select_plural_form, $count );		} 		/**		 * Returns the nplurals and plural forms expression from the Plural-Forms header.		 *		 * @since 2.8.0		 *		 * @param string $header		 * @return array{0: int, 1: string}		 */		public function nplurals_and_expression_from_header( $header ) {			if ( preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches ) ) {				$nplurals   = (int) $matches[1];				$expression = trim( $matches[2] );				return array( $nplurals, $expression );			} else {				return array( 2, 'n != 1' );			}		} 		/**		 * Makes a function, which will return the right translation index, according to the		 * plural forms header.		 *		 * @since 2.8.0		 *		 * @param int    $nplurals		 * @param string $expression		 * @return callable		 */		public function make_plural_form_function( $nplurals, $expression ) {			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( 2, 'n != 1' );			}		} 		/**		 * Adds parentheses to the inner parts of ternary operators in

Changelog

Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/pomo/translations.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.