Quit _locale from url in en language Symfony 3

Viewed 324

I have a project multi language with a <select> in all footer pages. When I'm in pages from my web, the url is like this: /es/privacy /en/privacy. Now I want delete the language in specific language, english.

if I'm in privacy page browsing in Spanish /es/privacy but if I'm browsing in English /privacy. This is an example of my routing.yml:

privacy_lang:
 path: /{_locale}/privacy
 defaults: { _controller: AppBundle:Documents:privacy }

privacy:
 path: /privacy
 defaults: { _controller: AppBundle:Documents:privacy }

And this my controller:

    /**
 * @Route("/privacy", name="privacy")
 * @Method("GET")
 */
public function privacyAction(Request $request)
{
    return $this->render('default/privacy.html.twig', [
        'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
    ]);
}

Now I have button in my page goes to Privacy Page:

<a class="privacy enllac-lower" href="{{ path('privacy_lang') }}">Privacy Policy</a>

How can I delete /en/ when user are browsing in english? Now if I go to http://www.myweb.com/privacy redirects to http://www.myweb.com/es/privacy.

0 Answers
Related