Skip to content

Commit f6370da

Browse files
committed
Remove translatable object handling from translators
1 parent b6033c3 commit f6370da

File tree

7 files changed

+12
-54
lines changed

7 files changed

+12
-54
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,12 @@
1111

1212
namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
1313

14-
use Symfony\Component\Translation\Translatable;
1514
use Symfony\Contracts\Translation\TranslatorInterface;
1615

1716
class StubTranslator implements TranslatorInterface
1817
{
1918
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
2019
{
21-
if ($id instanceof Translatable) {
22-
$parameters += $id->getParameters();
23-
$id = $id->getMessageId();
24-
}
25-
26-
$id = (string) $id;
27-
2820
return '[trans]'.strtr($id, $parameters).'[/trans]';
2921
}
3022
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getNotImplementingTranslatorBagInterfaceTranslatorClassNames()
108108

109109
class TranslatorWithTranslatorBag implements TranslatorInterface
110110
{
111-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null): string
111+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
112112
{
113113
}
114114
}

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,9 @@ public function __construct(TranslatorInterface $translator)
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null)
50+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
5151
{
52-
if ($id instanceof Translatable) {
53-
$parameters += $id->getParameters();
54-
$domain = $id->getDomain();
55-
$id = $id->getMessageId();
56-
}
57-
58-
$id = (string) $id;
59-
60-
$trans = $this->translator->trans($id, $parameters, $domain, $locale);
52+
$trans = $this->translator->trans($id = (string) $id, $parameters, $domain, $locale);
6153
$this->collectMessage($locale, $domain, $id, $trans, $parameters);
6254

6355
return $trans;

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,9 @@ public function __construct(TranslatorInterface $translator, LoggerInterface $lo
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null)
47+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
4848
{
49-
if ($id instanceof Translatable) {
50-
$parameters += $id->getParameters();
51-
$domain = $id->getDomain();
52-
$id = $id->getMessageId();
53-
}
54-
55-
$id = (string) $id;
56-
57-
$trans = $this->translator->trans($id, $parameters, $domain, $locale);
49+
$trans = $this->translator->trans($id = (string) $id, $parameters, $domain, $locale);
5850
$this->log($id, $domain, $locale);
5951

6052
return $trans;

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,12 @@ public function getFallbackLocales(): array
193193
/**
194194
* {@inheritdoc}
195195
*/
196-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null)
196+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
197197
{
198-
if ($id instanceof Translatable) {
199-
$parameters += $id->getParameters();
200-
$domain = $id->getDomain();
201-
$id = $id->getMessageId();
202-
}
203-
204198
if (null === $id || '' === $id) {
205199
return '';
206200
}
207201

208-
$id = (string) $id;
209-
210202
if (null === $domain) {
211203
$domain = 'messages';
212204
}

src/Symfony/Contracts/Translation/TranslatorInterface.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Contracts\Translation;
1313

14-
use Symfony\Component\Translation\Translatable;
15-
1614
/**
1715
* @author Fabien Potencier <fabien@symfony.com>
1816
*/
@@ -54,14 +52,14 @@ interface TranslatorInterface
5452
*
5553
* @see https://en.wikipedia.org/wiki/ISO_31-11
5654
*
57-
* @param string|Translatable $id The message id (may also be an object that can be cast to string)
58-
* @param array $parameters An array of parameters for the message
59-
* @param string|null $domain The domain for the message or null to use the default
60-
* @param string|null $locale The locale or null to use the default
55+
* @param string $id The message id (may also be an object that can be cast to string)
56+
* @param array $parameters An array of parameters for the message
57+
* @param string|null $domain The domain for the message or null to use the default
58+
* @param string|null $locale The locale or null to use the default
6159
*
6260
* @return string The translated string
6361
*
6462
* @throws \InvalidArgumentException If the locale contains invalid characters
6563
*/
66-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null);
64+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null);
6765
}

src/Symfony/Contracts/Translation/TranslatorTrait.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Contracts\Translation;
1313

1414
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15-
use Symfony\Component\Translation\Translatable;
1615

1716
/**
1817
* A trait to help implement TranslatorInterface and LocaleAwareInterface.
@@ -42,19 +41,12 @@ public function getLocale()
4241
/**
4342
* {@inheritdoc}
4443
*/
45-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null): string
44+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string
4645
{
47-
if ($id instanceof Translatable) {
48-
$parameters += $id->getParameters();
49-
$id = $id->getMessageId();
50-
}
51-
5246
if (null === $id || '' === $id) {
5347
return '';
5448
}
5549

56-
$id = (string) $id;
57-
5850
if (!isset($parameters['%count%']) || !is_numeric($parameters['%count%'])) {
5951
return strtr($id, $parameters);
6052
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy