Skip to content

Sort flag in translation:extract command doesn't seem to work #49250

@asispts

Description

@asispts

Symfony version(s) affected

6.2

Description

According to the help text

You can sort the output with the --sort flag:

  php bin/console translation:extract --dump-messages --sort=asc en AcmeBundle
  php bin/console translation:extract --dump-messages --sort=desc fr

However, when execute this command

php bin/console translation:extract --force --sort=asc --format=yaml --as-tree=3 en

will produce

app:
    tagline: __app.tagline
title:
    signin: __title.signin
    signin.subtitle: __title.signin.subtitle
action:
    signin_with_google: __action.signin_with_google
    forgot_password: __action.forgot_password
label:
    email: __label.email
    password: __label.password
button:
    signin: __button.signin
    signup: __button.signup

which doesn't seem to be sorted. Similar with XLIFF file

<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
    <file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
        <header>
            <tool tool-id="symfony" tool-name="Symfony" />
        </header>
        <body>
            <trans-unit id="0YNaGh4" resname="app.tagline">
                <source>app.tagline</source>
                <target>__app.tagline</target>
            </trans-unit>
            <trans-unit id="Qpet77t" resname="title.signin">
                <source>title.signin</source>
                <target>__title.signin</target>
            </trans-unit>
            <trans-unit id="mQx524n" resname="title.signin.subtitle">
                <source>title.signin.subtitle</source>
                <target>__title.signin.subtitle</target>
            </trans-unit>
            <trans-unit id="xmxEM1y" resname="action.signin_with_google">
                <source>action.signin_with_google</source>
                <target>__action.signin_with_google</target>
            </trans-unit>
            <trans-unit id="Bn6yTIX" resname="action.forgot_password">
                <source>action.forgot_password</source>
                <target>__action.forgot_password</target>
            </trans-unit>
            <trans-unit id="D2N6_cP" resname="label.email">
                <source>label.email</source>
                <target>__label.email</target>
            </trans-unit>
            <trans-unit id="9pvowqn" resname="label.password">
                <source>label.password</source>
                <target>__label.password</target>
            </trans-unit>
            <trans-unit id="IrKI5AG" resname="button.signin">
                <source>button.signin</source>
                <target>__button.signin</target>
            </trans-unit>
            <trans-unit id="WSGXkGL" resname="button.signup">
                <source>button.signup</source>
                <target>__button.signup</target>
            </trans-unit>
        </body>
    </file>
</xliff>

How to reproduce

Just execute this command in a Symfony project that use symfony/translation

php bin/console translation:extract --force --sort=asc en

Possible Solution

Output should be sorted by keywords.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions