src/I18n/Gettext/Translator.php
private static function fixTerseIfs($code, $inner = false)
    {
        /*
         * (?P<expression>[^?]+)   Capture everything up to ? as 'expression'
         * \?                      ?
         * (?P<success>[^:]+)      Capture everything up to : as 'success'
         * :                       :
         * (?P<failure>[^;]+)      Capture everything up to ; as 'failure'
         */
        \preg_match('/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', $code, $matches);

        // If no match was found then no terse if was present
        if (!isset($matches[0])) {
            return $code;
        }

        $expression = $matches['expression'];
        $success = $matches['success'];
        $failure = $matches['failure'];

        // Go look for another terse if in the failure state.
        $failure = self::fixTerseIfs($failure, true);
        $code = $expression.' ? '.$success.' : '.$failure;

        if ($inner) {
            return "($code)";
        }

        // note the semicolon. We need that for executing the code.
        return "$code;";
    }
private static function fixTerseIfs($code, $inner = false)
    {
        /*
         * (?P<expression>[^?]+)   Capture everything up to ? as 'expression'
         * \?                      ?
         * (?P<success>[^:]+)      Capture everything up to : as 'success'
         * :                       :
         * (?P<failure>[^;]+)      Capture everything up to ; as 'failure'
         */
        \preg_match('/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', $code, $matches);

        // If no match was found then no terse if was present
        if (!isset($matches[0])) {
            return $code;
        }

        $expression = $matches['expression'];
        $success = $matches['success'];
        $failure = $matches['failure'];

        // Go look for another terse if in the failure state.
        $failure = self::fixTerseIfs($failure, true);
        $code = $expression.' ? '.$success.' : '.$failure;

        if ($inner) {
            return "($code)";
        }

        // note the semicolon. We need that for executing the code.
        return "$code;";
    }
private static function fixTerseIfs ( $ code , $ inner = false ) { /*
         * (?P<expression>[^?]+)   Capture everything up to ? as 'expression'
         * \?                      ?
         * (?P<success>[^:]+)      Capture everything up to : as 'success'
         * :                       :
         * (?P<failure>[^;]+)      Capture everything up to ; as 'failure'
         */ \ preg_match ( '/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/' , $ code , $ matches ) ; // If no match was found then no terse if was present if ( ! isset ( $ matches [ 0 ] ) ) { return $ code ; } $ expression = $ matches [ 'expression' ] ; $ success = $ matches [ 'success' ] ; $ failure = $ matches [ 'failure' ] ; // Go look for another terse if in the failure state. $ failure = self :: fixTerseIfs ( $ failure , true ) ; $ code = $ expression . ' ? ' . $ success . ' : ' . $ failure ; if ( $ inner ) { return "($code)" ; } // note the semicolon. We need that for executing the code. return "$code;" ; }
This function will recursively wrap failure states in brackets if they contain a nested terse if.

This because PHP can not handle nested terse if's unless they are wrapped in brackets.

This code probably only works for the gettext plural decision codes.

return ($n==1 ? 0 : $n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2);
becomes
return ($n==1 ? 0 : ($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2));

@param string $code  the terse if string
@param bool   $inner If inner is true we wrap it in brackets

@return string A formatted terse If that PHP can work with.
This function will recursively wrap failure states in brackets if they contain a nested terse if .