Silex : allow user to change langage by clicking on html element and keeping clean URL

前端 未结 4 904
一生所求
一生所求 2021-01-19 07:18

I am using Silex and Twig for a website and I want to allow the user to change the langage of the site.

My problem

Right now, it works if I change the loca

4条回答
  •  情深已故
    2021-01-19 07:53

    The simple idea here is: how your application determines the language to be used to render the pages.

    solution #1 (your current solution) based on a URL parameter (that's _locale ), and fallback to some default value in case no URL-parameter given.
    So in this solution the translation component always looks for the selected language in the parameters bag prepared by the router component.

    Solution #2 put your language identifier inside a session variable. Your /new-langue page will have to set this session variable with the value it receives. and your router will populate the _locale parameter from that session variable.

    I may be able to provide some code snippets a bit later.

提交回复
热议问题