Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

New in Symfony 4.3: Extracting Translation Contents from PHP Files

Contributed by
Yonel Ceruto
in #30120.

The most time-consuming tasks when translating an application is to extract all the template contents to be translated and to keep all the translation files in sync. Symfony includes a command called translation:update that helps you with these tasks:

# updates the French translation with the missing strings found in templates/
$ php bin/console translation:update --dump-messages --force fr

As explained in the docs, the main limitation of this command is that it can only extract contents from templates. In Symfony 4.3, we've improved this command to also extract translation contents from PHP files, such as controllers and services.

Specifically, the command now introspects any PHP file/class defined as service which also injects (or autowires) the Symfony translator service. Consider for example this controller defined as a service:

use Symfony\Component\Translation\TranslatorInterface;

class SomeController extends AbstractController
    public function someAction(TranslatorInterface $translator)
        $message = $translator->trans('some_message_key');

        // ...

In Symfony 4.3, the some_message_key ID will be extracted when running the translation:update command, whereas in previous Symfony versions it was ignored.

Related to this change, we've also improved the extraction logic for PHP (Pull Request 31249), QT (Pull Request 31248) and PO (Pull Request 30909) files to include the file path and line number where the extracted strings were originally found.

New in Symfony 4.3: Extracting Translation Contents from PHP Files

Tweet this


Thank you for this contribution !
That's really good to hear ! Thanks for this addition ;)
Awesome work 👏 Thanks @yceruto
Excellent! Thanks very much
Nice ! Good job !
Wow this is awesome!
Thanks 👏👏
That's really nice, thank you!
Thanks :)
Thanks !

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.