I am using Silex and Twig for a website and I want to allow the user to change the langage of the site.
Right now, it works if I change the loca
In you case its just the matter of adding proper links to allow users so they can switch language. Rest of the work is already done by you. The language switcher dropdown must contain all supported languages including English. See below am example image.
Instead of redirecting the users to http://yourwebsite.com/[fr]/my-account you must redirect to a special method like http://www.yourwebsite.com/language_change?lang=fr. You will get HTTP_REFERRER in $_SERVER variable so you can redirect users back to the original page they were at. This way you can preserve users current visiting page/url.
Secondly, Ajax vs Redirect: Its better to use a redirect instead of AJAX. If you use AJAX you will increase the complicity to yourself.
When working with multilingual website, we must follow these best practices.
Specific routes per language
Menus, labels and forms
The content of the website
Extra: translate FOSUserBundle