【发布时间】:2021-03-31 21:16:05
【问题描述】:
我在表单类型中有翻译标签,例如:
$builder->add('island', EntityType::class, [
'class' => Island::class,
'choices' => $options['islands'],
'choice_attr' => function(Island $choice) {
// TODO move to template
return ['data-content' => $choice->getParent()
? '<span> ' . $choice->getName() . '</span>'
: '<b>' . $choice->getName() . '</b>'
];
},
'choice_label' => 'name',
'attr' => ['class' => 'selectpicker', 'title' => _('form.cafe.island.title')],
'required' => true,
'label' => false
])
如您所见,我尝试了传统的 _() 方式,但没有成功。
我试图在 poedit 的 po 文件中生成新标签,如下所示:
php bin/console translation:update --output-format=po --force hu
任何建议或想法都非常受欢迎。
提前致谢!
【问题讨论】:
-
您是否尝试将
Symfony\Contracts\Translation\TranslatorInterface服务注入到您的表单构建器中并调用它以使$this->translator->trans('form.cafe.island.title')转换您的值? -
@JeroenvanderLaan:谢谢,成功了一半。我现在可以手动将占位符添加到 po 文件中,然后翻译器进行翻译。任何想法,我怎样才能自动生成它?
标签: php forms symfony translation gettext