问题
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?
回答1:
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',
])
回答2:
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'
])
来源:https://stackoverflow.com/questions/38173571/translate-labels-in-formtype