Skip to content

Commit 148dca6

Browse files
committed
bug symfony#31275 [Translator] Preserve default domain when extracting strings from php files (Stadly)
This PR was squashed before being merged into the 3.4 branch (closes symfony#31275). Discussion ---------- [Translator] Preserve default domain when extracting strings from php files | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Use default domain when extracting translation strings with `null` as domain. Commits ------- ca77d9a [Translator] Preserve default domain when extracting strings from php files
2 parents a975d2b + ca77d9a commit 148dca6

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
226226
} elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
227227
$this->skipMethodArgument($tokenIterator);
228228
} elseif (self::DOMAIN_TOKEN === $item) {
229-
$domain = $this->getValue($tokenIterator);
229+
$domainToken = $this->getValue($tokenIterator);
230+
if ('' !== $domainToken) {
231+
$domain = $domainToken;
232+
}
230233

231234
break;
232235
} else {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function testExtraction($resource)
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',
5454
'concatenated message with heredoc and nowdoc' => 'prefixconcatenated message with heredoc and nowdoc',
55+
'default domain' => 'prefixdefault domain',
5556
],
5657
'not_messages' => [
5758
'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@
5555
<?php echo $view['translator']->trans('typecast', ['a' => (int) '123'], 'not_messages'); ?>
5656
<?php echo $view['translator']->transChoice('msg1', 10 + 1, [], 'not_messages'); ?>
5757
<?php echo $view['translator']->transChoice('msg2', ceil(4.5), [], 'not_messages'); ?>
58+
59+
<?php echo $view['translator']->trans('default domain', [], null); ?>

0 commit comments

Comments
 (0)