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

1
2
3
4
5
6
7
# 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

Jawira Portugal
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:

1
2
3
4
<trans-unit id="IsTxDdZ" resname="notification.comment_created">
    <source>notification.comment_created</source>
    <target>__notification.comment_created</target>
</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:

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

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

1
2
3
4
<trans-unit id="IsTxDdZ" resname="notification.comment_created">
    <source>notification.comment_created</source>
    <target></target>
</trans-unit>

Custom Sorting of Translation Contents

Daniel Gorgan
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:

1
$ 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:

1
2
$ php bin/console translation:extract --force --sort=desc tr
$ php bin/console translation:extract --force --sort=asc ko
Published in #Living on the edge