Answer the question
In order to leave comments, you need to log in
How to enable translation in symfony for forms?
I did everything according to the instructions.
app/config.yml file
framework:
#esi: ~
translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
assets_version: 0.1a
default_locale: "%locale%"
locale: ru
form:
maker: Производитель
category: Раздел
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'maker',
'entity',
array(
'class' => 'MyBundle:ItemMaker',
'property' => 'name',
'empty_value' => '-- Все --'
)
)
->add(
'category',
'entity',
array(
'class' => 'MyBundleCategory',
'property' => 'name',
'empty_value' => '-- Все --'
)
);
}
<div class="filterForm__fld">
<div class="filterForm__fld__title">
{{ form_label(form.maker) }}
</div>
{{ form_widget(form.maker, { 'attr': {'class': 'select select_t1 w100p'} }) }}
</div>
<div class="filterForm__fld">
<div class="filterForm__fld__title">
{{ form_label(form.category) }}
</div>
{{ form_widget(form.category, { 'attr': {'class': 'select select_t1 w100p'} }) }}
</div>
Answer the question
In order to leave comments, you need to log in
do not make the "forms:" section in messages.ru.yml, put the translation directly as it is written on the page. You have maker and category fields in the form, and they are displayed on the page as Maker and Category. So?
Write in translation like this:
Maker: Создатель
Category: Категория
$builder
->add(
'maker',
'entity',
array(
'label' => 'form.maker',
'class' => 'MyBundle:ItemMaker',
'property' => 'name',
'empty_value' => '-- Все --'
)
)
->add(
'category',
'entity',
array(
'label' => 'form.category',
'class' => 'MyBundleCategory',
'property' => 'name',
'empty_value' => '-- Все --'
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question