I'm using the internal Translation extension in Symfony2 to create a message.en.yml file with the translations. While most of the elements are recorded with a distinct name, the field names( or possibly the entity properties, I'm not sure) are cataloged with only their names. This makes it very difficult to handle them.
For example, this a sample of my message.en.yml:
address.contactdocumentnumber.list: __address.contactdocumentnumber.list
address.contactdocumentnumber.add.new: __address.contactdocumentnumber.add.new
contactDocumentnumber: __contactDocumentnumber
issuingAuthority: __issuingAuthority
documentType: __documentType
As you can see the field names: contactDocumentnumber, issuingAuthority, documentType are stored with only their names where what I want is something like address.contactdocumentnumber.form.label.issuingAuthority
How can I change this? And more importantly, where is the template for translations located in a Symfony2 project?
I have noticed that when I change the label in the Form Builder, it does show in my form. But when I run the command "php app/console translate:update --force en MyByndle" the field name is still the same eg __fieldname. Is it possible it takes the name from somewhere else, like the entity for example?
By default Symfony guesses the label based on the name of the field. So a field named some_field
will get the label Some field
. If you want to override that, you can pass a label
option with your translatable string when building the field. For example:
$builder->add('some_field', 'text', [
'label' => 'section.some_field_label'
]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.