Gettext_Translations::parenthesize_plural_exression()publicWP 2.8.0

Устарела с версии 6.5.0. Больше не поддерживается и может быть удалена. Используйте Plural_Forms class.

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

Метод класса: Gettext_Translations{}

Хуков нет.

Возвращает

Строку. the expression with parentheses added

Использование

$Gettext_Translations = new Gettext_Translations();
$Gettext_Translations->parenthesize_plural_exression( $expression );
$expression(строка) (обязательный)
the expression without parentheses

Заметки

Список изменений

С версии 2.8.0 Введена.
Устарела с 6.5.0 Use the Plural_Forms class instead.

Код Gettext_Translations::parenthesize_plural_exression() WP 6.5.2

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, ';' );
}