Symfony将用户重定向到url国家/地区

I'm looking for a PHP / Symfony code to redirect the user to another link according to his place of connection www.mondomain.fr/fr and www.mondomaine.fr/pt etc ... How can I do this ? I have included in my roads this already:

/**
 * @Route("/{_locale}", name="homepage")
 *
 */
public function indexAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $boutton = $em->getRepository('AppBundle:Boutton')->findAll();
    $image = $em->getRepository('AppBundle:Images')->findAll();

    // replace this example code with whatever you need
    return $this->render('default/index.html.twig', array(
        'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        'boutton' => $boutton,
        'images' => $image
    ));
}

Thank you

One of the solutions (not a PHP one) is to redirect based on browser language, you can find answer here.

You can also detect IP and redirect based on that, you can use this library to get the country/locale of the IP address and then redirect based on that.