New in Symfony 7.2: Improved Translation Extractor


Symfony provides the translation:extract command to extract all
translatable content from Twig templates and PHP code (e.g. forms):

# extracts all content that should be translated into Turkish
# and outputs them, but it doesn't update the translation catalog
$ php bin/console translation:extract --dump-messages tr

# updates the Korean translation catalog with all missing content
# compared to the application's translatable content
$ php bin/console translation:extract --force ko

In Symfony 7.2 we're enhancing this command with new options.

Empty Pending Translations

Contributed by
Jawira Portugal
in
#58506

By default, when the translation:extract command finds new content, it
creates a new entry for translation using the same content as both the source
and the pending translation. For example, if your application uses the XLIFF
format for translations and templates use translation keys instead of real
content, you'll see entries like this in the translation catalog:

<trans-unit id="IsTxDdZ" resname="notification.comment_created">
<source>notification.comment_createdsource>
<target>__notification.comment_createdtarget>
trans-unit>

The __ prefix is added to help you quickly spot untranslated content in your
application. Alternatively, you can leave the pending translation completely empty
when creating new entries in the translation catalog.
To do so, use the new --no-fill option introduced in Symfony 7.2:

$ php bin/console translation:extract --force --no-fill ko

When adding the --no-fill option, the new entry will look like this:

<trans-unit id="IsTxDdZ" resname="notification.comment_created">
<source>notification.comment_createdsource>
<target>target>
trans-unit>

Custom Sorting of Translation Contents

Contributed by
Daniel Gorgan
in
#58408

The translation:extract command includes a --sort option to display the
translated content sorted alphabetically (ASC or DESC) when showing messages
in the terminal:

$ php bin/console translation:extract --dump-messages --sort=desc tr

In Symfony 7.2, we're enhancing this option to also apply to translation
catalog files. When using it in combination with the --force option, you
can now sort the content of the translation catalog alphabetically:

$ php bin/console translation:extract --force --sort=desc tr
$ php bin/console translation:extract --force --sort=asc ko

Sponsor the Symfony project.