8000 minor #12579 [Translation] [2.6] Upgrade information for LoggingTrans… · symfony/symfony@c4902d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4902d8

Browse files
committed
minor #12579 [Translation] [2.6] Upgrade information for LoggingTranslator (derrabus)
This PR was merged into the 2.6 branch. Discussion ---------- [Translation] [2.6] Upgrade information for LoggingTranslator | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | none When upgrading a Symfony 2.5 project to the 2.6 branch, I noticed that the `@translator` service was changed. In the affected project, we've had a service that depends on the `@translator` service and uses a type hint to ensure that a `Translator` instance is passed to the constructor. With the introduction of the `LoggingTranslator` class (PR #10887), this type hint now fails. I have added a small note to ` UPGRADE-2.6.md` in case more people stumble across this changed behavior. Commits ------- cd55a81 Upgrade information for the Translation component regarding the new LoggingTranslator class.
2 parents 48e6f7a + cd55a81 commit c4902d8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

UPGRADE-2.6.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,43 @@ $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
364364
Then enjoy dumping variables by calling `dump($var)` anywhere in your PHP
365365
and `{% dump var %}` or `{{ dump(var) }}` in Twig. Dumps are displayed
366366
**in the web debug toolbar**.
367+
368+
Translation
369+
-----------
370+
371+
With `LoggingTranslator`, a new translator class is introduced with Symfony
372+
2.6. By default, the `@translator` service is referring to this class in the
373+
debug environment.
374+
375+
If you have own services that depend on the `@translator` service and expect
376+
this service to be an instance of either
377+
`Symfony\Component\Translation\Translator` or
378+
`Symfony\Bundle\FrameworkBundle\Translation\Translator`, e.g. by type-hinting
379+
for either of these classes, you will need to change that type hint. You can
380+
use the `TranslatorInterface` to be on the safe side for future changes.
381+
382+
Before:
383+
384+
```php
385+
use Symfony\Component\Translation\Translator;
386+
387+
class MyService {
388+
public function __construct(Translator $translator)
389+
{
390+
...
391+
}
392+
}
393+
```
394+
395+
After:
396+
397+
```php
398+
use Symfony\Component\Translation\TranslatorInterface;
399+
400+
class MyService {
401+
public function __construct(TranslatorInterface $translator)
402+
{
403+
...
404+
}
405+
}
406+
```

0 commit comments

Comments
 (0)
0