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

Vytvořeno 3y | 19. 11. 2021 10:20:10


Chcete-li přidat komentář, přihlaste se

Ostatní příspěvky v této skupině

New in Symfony 7.3: Invokable Commands and Input Attributes

This is the first article in a series showcasing the most important new features introduced by Symfony 7.3, which will be released at the end of May 2025.

22. 4. 2025 9:10:36 | Symfony
A Week of Symfony #955 (April 14–20, 2025)

This week, the upcoming Symfony 7.3 version improved the AsAlias attribute by adding a new argument, introduced Clock support for UriSigner, and refined the return type of the ContainerInterface::get(

20. 4. 2025 8:30:06 | Symfony
SymfonyOnline June 2025: Rethinking File Handling in Symfony

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

16. 4. 2025 16:30:02 | Symfony
SymfonyLive Paris 2025: Recap and replay!

SymfonyLive Paris 2025 took place three weeks ago — a big thank you to everyone who joined us! The conference was held entirely in French, and now you can relive the best moments: replays, hig

15. 4. 2025 14:50:24 | Symfony
A Week of Symfony #954 (April 7–13, 2025)

This week, Symfony 7.3 entered its "feature freeze" period in preparation for its release at the end of May 2025. Development activity focused on refining and polishing its new features, including a n

13. 4. 2025 9:40:02 | Symfony
SymfonyOnline June 2025: What's New in Symfony 7.3

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

10. 4. 2025 16:40:34 | Symfony
SymfonyCon Amsterdam 2025: Last days to enjoy early bird tickets!

The international Symfony conference of the year, SymfonyCon Amsterdam 2025, will take place in the Netherlands on November 27 & 28, 2025!

⏳ Early bird registration ends this Wednesday! D

8. 4. 2025 9:10:13 | Symfony