From df73ebf00f4a1ac26e13a7187a6dd32836e0328f Mon Sep 17 00:00:00 2001 From: Stadly Date: Wed, 23 Jan 2019 11:01:37 +0100 Subject: [PATCH] [Translation] Concatenated translation messages --- .../Translation/Extractor/PhpExtractor.php | 22 ++++++++++++++----- .../Tests/Extractor/PhpExtractorTest.php | 1 + .../fixtures/extractor/translation.html.php | 8 +++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Translation/Extractor/PhpExtractor.php b/src/Symfony/Component/Translation/Extractor/PhpExtractor.php index bf7da431a7f1..7f4c6e60394c 100644 --- a/src/Symfony/Component/Translation/Extractor/PhpExtractor.php +++ b/src/Symfony/Component/Translation/Extractor/PhpExtractor.php @@ -156,9 +156,14 @@ private function getValue(\Iterator $tokenIterator) { $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 @@ private function getValue(\Iterator $tokenIterator) 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; } diff --git a/src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php b/src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php index f6a17d00c0f6..73ccb07cfb07 100644 --- a/src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php +++ b/src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php @@ -51,6 +51,7 @@ public function testExtraction($resource) $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', diff --git a/src/Symfony/Component/Translation/Tests/fixtures/extractor/translation.html.php b/src/Symfony/Component/Translation/Tests/fixtures/extractor/translation.html.php index 11261311a1be..094660335272 100644 --- a/src/Symfony/Component/Translation/Tests/fixtures/extractor/translation.html.php +++ b/src/Symfony/Component/Translation/Tests/fixtures/extractor/translation.html.php @@ -32,6 +32,14 @@ ['%count%' => 10] ); ?> +trans('concatenated'.' message'.<< + trans('other-domain-test-no-params-short-array', [], 'not_messages'); ?> trans('other-domain-test-no-params-long-array', [], 'not_messages'); ?>