Gettext_Translations::parenthesize_plural_exression() WordPress Method

The Gettext_Translations::parenthesize_plural_exression() method is used to generate a string containing a parenthesized singular and plural form of a string. The first argument is the singular form, and the second argument is the plural form.

Gettext_Translations::parenthesize_plural_exression( string $expression ) #

Adds parentheses to the inner parts of ternary operators in plural expressions, because PHP evaluates ternary oerators from left to right


Parameters

$expression

(string)(Required)the expression without parentheses


Top ↑

Return

(string) the expression with parentheses added


Top ↑

Source

File: wp-includes/pomo/translations.php

		public function parenthesize_plural_exression( $expression ) {
			$expression .= ';';
			$res         = '';
			$depth       = 0;
			for ( $i = 0; $i < strlen( $expression ); ++$i ) {
				$char = $expression[ $i ];
				switch ( $char ) {
					case '?':
						$res .= ' ? (';
						$depth++;
						break;
					case ':':
						$res .= ') : (';
						break;
					case ';':
						$res  .= str_repeat( ')', $depth ) . ';';
						$depth = 0;
						break;
					default:
						$res .= $char;
				}
			}
			return rtrim( $res, ';' );
		}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.