Vincent J.
Vincent J.

Reputation: 35

How implement translation link with Symfony 2?

I had setup translation for a symfony 2 application. It works well when i change the "local" setting in "parameters.yml", but i want to use a link on each page to switch languages (2 languages used). Do you know a simple method to implement this link (and if it's possible, not change the current URLs in the application)?

Notes: There is the FOSUserBundle.

Thanks

Upvotes: 1

Views: 235

Answers (1)

JSamson
JSamson

Reputation: 21

I have implemented a little local switcher for my own project.

It's easy to do just create a twig with this link generated for each languages and you'll be able to switch your website local easily :

  <a href="{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'fr'})) }}">
  LANGUAGE
</a>

Also, if you want a bundle to help you with your translation try this one : https://github.com/lexik/LexikTranslationBundle

Upvotes: 1

Related Questions