Gettext_Translations::parenthesize_plural_exression()
最后更新于:2021-11-25 19:52:31
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
参数
- $expression
-
(string) (Required) the expression without parentheses
响应
(string) the expression with parentheses added
源文件
文件: gc-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, ';' );
}