giannisf
giannisf

Reputation: 2599

Translate labels in FormType

How can I translate labels values in Form builder.

Example:

->add('google_analytics_key', TextType::class, [
                'label' => 'Analytics Key'
            ])

the "Analytics Key" is the value for the default locale.

I am using the form with rows:

{{ form_row(myForm.google_analytics_key) }}

This renders the label with input type as well, so I cannot use the trans command.

Is there something built in Symfony/Twig or I must implement the form manually?

Upvotes: 0

Views: 2894

Answers (2)

habibun
habibun

Reputation: 1630

This is for yml configuration.

First Check:

app/config/config.yml

framework: translator: { fallbacks: [en] }

Then Inside translations folder: add your transalation file and add:::

messages.en.yml

test: Analytics Key

and last just add the reference:

->add('google_analytics_key', TextType::class, [
            'label' => 'test'
        ])

Upvotes: 1

Shay Altman
Shay Altman

Reputation: 2760

You can add the domain of your translation and the key

For example:

->add('google_analytics_key', TextType::class, [
    'translation_domain' => '<your file name>',//for example 'messages'
    'label' => 'app.analytics_key',
            ])

Upvotes: 2

Related Questions