Skip to content

Commit df73ebf

Browse files
Stadlynicolas-grekas
authored andcommitted
[Translation] Concatenated translation messages
1 parent aca3d2c commit df73ebf

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/Symfony/Component/Translation/Extractor/PhpExtractor.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,14 @@ private function getValue(\Iterator $tokenIterator)
156156
{
157157
$message = '';
158158
$docToken = '';
159+
$docPart = '';
159160

160161
for (; $tokenIterator->valid(); $tokenIterator->next()) {
161162
$t = $tokenIterator->current();
163+
if ('.' === $t) {
164+
// Concatenate with next token
165+
continue;
166+
}
162167
if (!isset($t[1])) {
163168
break;
164169
}
@@ -169,19 +174,24 @@ private function getValue(\Iterator $tokenIterator)
169174
break;
170175
case T_ENCAPSED_AND_WHITESPACE:
171176
case T_CONSTANT_ENCAPSED_STRING:
172-
$message .= $t[1];
177+
if ('' === $docToken) {
178+
$message .= PhpStringTokenParser::parse($t[1]);
179+
} else {
180+
$docPart = $t[1];
181+
}
173182
break;
174183
case T_END_HEREDOC:
175-
return PhpStringTokenParser::parseDocString($docToken, $message);
184+
$message .= PhpStringTokenParser::parseDocString($docToken, $docPart);
185+
$docToken = '';
186+
$docPart = '';
187+
break;
188+
case T_WHITESPACE:
189+
break;
176190
default:
177191
break 2;
178192
}
179193
}
180194

181-
if ($message) {
182-
$message = PhpStringTokenParser::parse($message);
183-
}
184-
185195
return $message;
186196
}
187197

src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function testExtraction($resource)
5151
$expectedHeredoc => 'prefix'.$expectedHeredoc,
5252
$expectedNowdoc => 'prefix'.$expectedNowdoc,
5353
'{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',
54+
'concatenated message with heredoc and nowdoc' => 'prefixconcatenated message with heredoc and nowdoc',
5455
],
5556
'not_messages' => [
5657
'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',

src/Symfony/Component/Translation/Tests/fixtures/extractor/translation.html.php

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
['%count%' => 10]
3333
); ?>
3434

35+
<?php echo $view['translator']->trans('concatenated'.' message'.<<<EOF
36+
with heredoc
37+
EOF
38+
.<<<'EOF'
39+
and nowdoc
40+
EOF
41+
); ?>
42+
3543
<?php echo $view['translator']->trans('other-domain-test-no-params-short-array', [], 'not_messages'); ?>
3644

3745
<?php echo $view['translator']->trans('other-domain-test-no-params-long-array', [], 'not_messages'); ?>

0 commit comments

Comments
 (0)