1

I use almost standard CRUD form rendering in Twig:

{{ form_start(form, {'attr' : {'class' : 'new_edit_form'}}) }}
{{ form_widget(form) }}
<input type="submit" value="{{ 'default.new.create'|trans }}"/>
{{ form_end(form) }}

In this case all inputs have labels with upper case property names:

Title 
Description
Date

I have translations enabled in my project and Twig tries to translate these words, but in my dictionaries all properties have ids like field.property_name. So I want to go through all form inputs and rewrite all labels making them lower case and adding 'field.' prefix. How can I do this in cycle?

Symfony 3.4

A.L
  • 10,259
  • 10
  • 67
  • 98
Audiophile
  • 970
  • 2
  • 8
  • 20
  • not sure what framework you are using, but generally , we have this function: __($field.property_name), which will return you a translated text if there is one, else use your default language – Shuyi Jul 28 '17 at 19:46
  • Possible duplicate of [Translate labels in FormType](https://stackoverflow.com/questions/38173571/translate-labels-in-formtype) – jkucharovic Jul 30 '17 at 12:03

2 Answers2

0

In order to overwrite the translations you need to add the messages.en.yml to the app/YourBundle/Resources/translations and overwrite the messages you want like: field.property_name: Your label here

This can help: How to translate labels in symfony2 forms with messages.en.yml?

Keloo
  • 1,368
  • 1
  • 17
  • 36
0

You can define a specific label for each field:

$builder->add('save', TextType::class, array(
    'label' => 'field.sth'
))
eeXBee
  • 133
  • 7