Search code examples
symfonylocaletranslatetranslators

Symfony change website's language


I am building a website using Symfony. I am wondering how can I change the language of my website by pressing a button. Say I have two links in the footer (English and German) and when I click any of them, the whole website and all future views I access will remember my choice of language.

There are numerous websites who have this facility and I am wondering how can I achieve this goal.

Thank you!


Solution

  • Recommend checking out the jms/i18n-routing-bundle. You can use buttons or links to change the locale (language) and once changed the site will remain on that language. Just a bit of advice, use the "prefix" strategy when you set it up so that your site's urls will always be domain.com/language/.....

    You'll have to learn how to use the translation bundle and setup translation files as well as having to learn how to setup Twig for translations, using the translation in your services and forms, but once you get the hang of it, it is really easy but time consuming.