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 65ac028

Browse filesBrowse files
committed
Remove translatable object handling from translators
1 parent b6033c3 commit 65ac028
Copy full SHA for 65ac028

File tree

7 files changed

+9
-50
lines changed
Filter options

7 files changed

+9
-50
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php
-8Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/DataCollectorTranslator.php
+1-9Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,8 @@ 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-
6052
$trans = $this->translator->trans($id, $parameters, $domain, $locale);
6153
$this->collectMessage($locale, $domain, $id, $trans, $parameters);
6254

‎src/Symfony/Component/Translation/LoggingTranslator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/LoggingTranslator.php
+1-9Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,8 @@ 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-
5749
$trans = $this->translator->trans($id, $parameters, $domain, $locale);
5850
$this->log($id, $domain, $locale);
5951

‎src/Symfony/Component/Translation/Translator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Translator.php
+1-9Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Translation/TranslatorInterface.php
+4-6Lines changed: 4 additions & 6 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,10 +52,10 @@ 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
*

‎src/Symfony/Contracts/Translation/TranslatorTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Translation/TranslatorTrait.php
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,12 @@ public function getLocale()
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function trans($id, array $parameters = [], string $domain = null, string $locale = null): string
45+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string
4646
{
47-
if ($id instanceof Translatable) {
48-
$parameters += $id->getParameters();
49-
$id = $id->getMessageId();
50-
}
51-
5247
if (null === $id || '' === $id) {
5348
return '';
5449
}
5550

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.