[Translation] Concatenated translation messages

This commit is contained in:
Stadly 2019-01-23 11:01:37 +01:00 committed by Nicolas Grekas
parent aca3d2c90d
commit df73ebf00f
3 changed files with 25 additions and 6 deletions

View File

@ -156,9 +156,14 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
$message = '';
$docToken = '';
$docPart = '';
for (; $tokenIterator->valid(); $tokenIterator->next()) {
$t = $tokenIterator->current();
if ('.' === $t) {
// Concatenate with next token
continue;
}
if (!isset($t[1])) {
break;
}
@ -169,19 +174,24 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
break;
case T_ENCAPSED_AND_WHITESPACE:
case T_CONSTANT_ENCAPSED_STRING:
$message .= $t[1];
if ('' === $docToken) {
$message .= PhpStringTokenParser::parse($t[1]);
} else {
$docPart = $t[1];
}
break;
case T_END_HEREDOC:
return PhpStringTokenParser::parseDocString($docToken, $message);
$message .= PhpStringTokenParser::parseDocString($docToken, $docPart);
$docToken = '';
$docPart = '';
break;
case T_WHITESPACE:
break;
default:
break 2;
}
}
if ($message) {
$message = PhpStringTokenParser::parse($message);
}
return $message;
}

View File

@ -51,6 +51,7 @@ EOF;
$expectedHeredoc => 'prefix'.$expectedHeredoc,
$expectedNowdoc => 'prefix'.$expectedNowdoc,
'{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples' => 'prefix{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
'concatenated message with heredoc and nowdoc' => 'prefixconcatenated message with heredoc and nowdoc',
],
'not_messages' => [
'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',

View File

@ -32,6 +32,14 @@ EOF
['%count%' => 10]
); ?>
<?php echo $view['translator']->trans('concatenated'.' message'.<<<EOF
with heredoc
EOF
.<<<'EOF'
and nowdoc
EOF
); ?>
<?php echo $view['translator']->trans('other-domain-test-no-params-short-array', [], 'not_messages'); ?>
<?php echo $view['translator']->trans('other-domain-test-no-params-long-array', [], 'not_messages'); ?>