Skip to content

Instantly share code, notes, and snippets.

@sufimalek
Created March 29, 2018 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sufimalek/29a89f45616ff7fcedb035112aca31dd to your computer and use it in GitHub Desktop.
Save sufimalek/29a89f45616ff7fcedb035112aca31dd to your computer and use it in GitHub Desktop.
internationalization in symfony2/3
/**
* @Route("/change/locale/{current}/{locale}/", name="locale_change")
*/
public function setLocaleAction($current, $locale)
{
$this->get('request')->setLocale($locale);
$referer = str_replace($current,$locale,$this->getRequest()->headers->get('referer'));
return $this->redirect($referer);
}
<li {% if app.request.locale == language.locale %} class="selected" {% endif %}>
<a href="{{ path('locale_change', { 'current' : app.request.locale, 'locale' : language.locale } ) }}"> {{ language.locale }}</a>
</li>
https://stackoverflow.com/questions/7903477/symfony2-default-locale-in-routing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment