New in Symfony 5.4: Translation Improvements

Renamed the Translation Update Command

        Contributed by Mathieu Santostefano 
        in #43758.

The well-known translation:update command extracts translatable contents from templates, controllers, and some PHP files. It's useful to automatically create (and update) the translation files of your applications. Although the command "updates" the translation files, its main feature is to "extract" translatable contents. That's why in Symfony 5.4 we've updated its name from translation:update to translation:extract. You can still use the old name, but you should update it as soon as possible because the old name will no longer work in Symfony 6.0.

GitHub Actions Integration

        Contributed by Yannis Foucher 
        in #39828.

The lint:xliff command has added a new github output format so you can see the translation errors properly formatted in the GitHub Actions output. Use the following command to validate your translation files inside GitHub Actions:

    1
    $ php bin/console lint:xliff translations/ --format=github

Translatable Help Messages

        Contributed by Patrick Landolt 
        in #41717.

In Symfony 5.2 we introduced Translatable objects, which include not only the contents to translate but all the information needed to do so (translation parameters, translation domain, etc.) In Symfony 5.4 we're improving Symfony Forms to allow these objects as the help message of form fields too:

    1

2 3 4 5 use Symfony\Component\Translation\TranslatableMessage;

$builder->add('zipCode', null, [ 'help' => new TranslatableMessage('admin.zip_code', ['%current_zip%' => $order->getZipCode()], 'admin'), ]);

Translatable Parameters in Translatable Objects

        Contributed by kylekatarnls 
        in #41858.

Another improvement related to Translatable objects is that parameters can now also be translatable. This may sound confusing, but consider the following message:

    1

2 3 // message 'invoice.status' (English) 'This invoice is in "%status%" status' (Spanish) 'El estado de la factura es "%status%"'

In addition to translating the entire message, the %status% parameter must be translated as well. In Symfony 5.4 you can solve that by making the parameter a TranslatableMessage object:

    1

2 3 4 5 $message = new TranslatableMessage('invoice.status', ['%status%' => new TranslatableMessage('status.draft')]); echo $message->trans($translator, 'en'); // This invoice is in "draft" status echo $message->trans($translator, 'es'); // El estado de la factura es "borrador"

                Sponsor the Symfony project.

https://symfony.com/blog/new-in-symfony-5-4-translation-improvements?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Created 3y | Nov 19, 2021, 10:20:10 AM


Login to add comment

Other posts in this group

Just one month to go before SymfonyLive Paris 2025 workshops begin!

SymfonyLive Paris 2025, conference in French language only, will already start in 1 month with the workshops! Have a look on the topics and join us! Schedule details are available here.

📣

Feb 25, 2025, 3:20:33 PM | Symfony
New Core Team Members, 2025 Edition

A few weeks ago, I had the pleasure of announcing the formation of the Symfony UX Core Team, a dedicated group working to enhance the frontend development experience within the Symfony ecosystem. Toda

Feb 24, 2025, 4:20:03 PM | Symfony
SymfonyLive Paris 2025 : Du lego de composants pour un bundle Gotenberg !

SymfonyLive Paris 2025, conference in French language only, will take place from March 27 to 28! The schedule is currently being revealed as we go along. More details are available here.

Al

Feb 24, 2025, 1:50:07 PM | Symfony
A Week of Symfony #947 (17-23 February 2025)

This week, development activity focused on new security features. The upcoming Symfony 7.3 version added support for security voters to explain their vote, improved the IsGranted attribute to allow us

Feb 23, 2025, 10:10:09 AM | Symfony
SymfonyLive Berlin 2025: Agentic Applications with Symfony

SymfonyLive Berlin 2025, conference held in English, will take place from April 1 to 4! The schedule is being revealed gradually. More details are available here.

We’re thrilled to announce

Feb 21, 2025, 9:20:12 AM | Symfony
SymfonyLive Paris 2025 : Postgres pour vos besoins NoSQL

SymfonyLive Paris 2025, conference in French language only, will take place from March 27 to 28! The schedule is currently being revealed as we go along. More details are available here.

Al

Feb 20, 2025, 10:10:13 AM | Symfony
SymfonyLive Berlin 2025: Asynchronous PHP

SymfonyLive Berlin 2025, conference held in English, will take place from April 1 to 4! The schedule is being revealed gradually. More details are available here.

We’re thrilled to announce

Feb 19, 2025, 8:40:05 AM | Symfony