Vardius Vardius - 1 year ago 99
PHP Question

Translate form to custom set locale

Hi i have a use case where i want to translate form to the custom locale then that one set in request

I tried to do something like

$tmpLocale = $request->getLocale();
$form = $this->createForm(new DataType());
$formView = $form->renderView();

return $this->render('AppBundle:Data:edit.html.twig', array(
'data' => $data,
'form' => $formView,

but it doesnt work, how can i make it work this ?
i need form labels to be translated as this custom locale.

Answer Source

I did it by simple change locale at translator service.

$tmpLocale = $this->get('translator')->getLocale();
$form = $this->createForm(new DataType());
$formView = $form->createView();

And this works fine. No need for advanced solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download