O
O
Onatskyi2019-05-14 19:39:19
PHP
Onatskyi, 2019-05-14 19:39:19

How to implement localization in PHP MVC?

Hello!
Tell me how to implement localization via URL in MVC pattern in PHP?
In this form:
site.com/locale/contacts Many
thanks in advance!
PS At least the question is where and how to extract the locale from the URL.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitsliputsli, 2019-05-14
@Vitsliputsli

Extract in the controller, translate in the view.

A
Alexander, 2019-05-14
@AleksandrB

You need to extract it in the router, if I correctly understood the goals.

$url = trim($_SERVER['REQUEST_URI'], '/');
$pos = strripos($url, "?");
if ($pos)
   $url = stristr($url, '?', true);

from the line site.com/locale/contacts we will get locale/contacts
Even if the url has get parameters - site.com/locale/contacts?some=dame , the $url will still contain locale/contacts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question