Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13d1d76

Browse filesBrowse files
bug #29961 [Translation] Concatenated translation messages (Stadly)
This PR was squashed before being merged into the 3.4 branch (closes #29961). Discussion ---------- [Translation] Concatenated translation messages | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29956 | License | MIT | Doc PR | none Concatenated translation messages are now treated correctly. Commits ------- df73ebf [Translation] Concatenated translation messages
2 parents 765539b + df73ebf commit 13d1d76
Copy full SHA for 13d1d76

File tree

Expand file treeCollapse file tree

3 files changed

+25
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Extractor/PhpExtractor.php
+16-6Lines changed: 16 additions & 6 deletions
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/fixtures/extractor/translation.html.php
+8Lines changed: 8 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.