Forwarding to the correct language

Need to implement a competent redirect redirect to a page with the correct language.

Ie we have a site: site.ru

It has 2 languages: site.ru/ru and site.ru/en, respectively.

It is required that when entering the site.ru, the language should be correctly selected, and redirected to the appropriate section of the language, the site.ru/ru or site.ru/en

also, if the user for some reason switched to the site.ru/news, or the site.ru/news/today he was also transferred to the corresponding page with the language site.ru/{ru or en}/news and site.ru/{ru or en}/news/today respectively

It is also required to save the post request, that is, if there was a request to the site.ru?User=1, should redirect the site.ru/{ru or en}?User=1

Multilingualism on the site is implemented, the corresponding language is written in dispatch: beforeExecuteRoute in this way: $ session-> set('lang', $lang);

At the moment, everything has been done with a crutch. If there is no language in the address (ru or en), then we redirect to the controller that determines the language from the session ($ this-> session-> get ('lang');) and then simply transfer it to the corresponding language.

A simpler solution might be to not have separate language-based URLs, and just rely on the SESSION's language value.

So if someone visits site.ru/ with no language set, you either forward them to a controller that determines their language, or you have some code in your base controller that determines it. The second option would be better, because then that functionality could be run on any page, not just the homepage.

Then just build it into your view that you check the language before determining which templates or language files to use.

This will also simplify POST forwarding, which is a pain-in-the-ass.