嗨,我有一个用例,我想将表单转换为自定义语言环境,然后在请求中设置一个
我试图做类似的事情
$tmpLocale = $request->getLocale();
$request->setLocale('es');
$form = $this->createForm(new DataType());
$formView = $form->renderView();
$request->setLocale($tmpLocale);
return $this->render('AppBundle:Data:edit.html.twig', array(
'data' => $data,
'form' => $formView,
));
但它不起作用,我该如何使其起作用?我需要将表单标签翻译为该自定义语言环境。
我在翻译服务中通过简单的更改区域设置做到了这一点。
$tmpLocale = $this->get('translator')->getLocale();
$this->get('translator')->setLocale('es');
$form = $this->createForm(new DataType());
$formView = $form->createView();
$this->get('translator')->setLocale($tmpLocale);
而且这很好。无需高级解决方案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句