Adds parentheses to the inner parts of ternary operators in plural expressions, because PHP evaluates ternary oerators from left to right
(string) (Required) the expression without parentheses
(string) the expression with parentheses added
File: wp-includes/pomo/translations.php
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, ';' ); }
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/gettext_translations/parenthesize_plural_exression