Skip to content

Commit

Permalink
bug #31275 [Translator] Preserve default domain when extracting strin…
Browse files Browse the repository at this point in the history
…gs from php files (Stadly)

This PR was squashed before being merged into the 3.4 branch (closes #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
  • Loading branch information
fabpot committed Apr 27, 2019
2 parents a975d2b + ca77d9a commit 148dca6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Symfony/Component/Translation/Extractor/PhpExtractor.php
Expand Up @@ -226,7 +226,10 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
} elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
$this->skipMethodArgument($tokenIterator);
} elseif (self::DOMAIN_TOKEN === $item) {
$domain = $this->getValue($tokenIterator);
$domainToken = $this->getValue($tokenIterator);
if ('' !== $domainToken) {
$domain = $domainToken;
}

break;
} else {
Expand Down
Expand Up @@ -52,6 +52,7 @@ public function testExtraction($resource)
$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',
'default domain' => 'prefixdefault domain',
],
'not_messages' => [
'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',
Expand Down
Expand Up @@ -55,3 +55,5 @@
<?php echo $view['translator']->trans('typecast', ['a' => (int) '123'], 'not_messages'); ?>
<?php echo $view['translator']->transChoice('msg1', 10 + 1, [], 'not_messages'); ?>
<?php echo $view['translator']->transChoice('msg2', ceil(4.5), [], 'not_messages'); ?>

<?php echo $view['translator']->trans('default domain', [], null); ?>

0 comments on commit 148dca6

Please sign in to comment.