I Have Url structure for multi language system like this:
for default language ie: en
localhost/cms
And Another Language Like:
localhost/cms/fr
localhost/cms/de
localhost/cms/es
Now I have this function for detect empty url language short name parts and set to default language:
function urlss(){
$uri = $_SERVER['REQUEST_URI'];
$languages = ['en', 'fr', 'es', 'de'];
// this is my default language
$defaultLang = 'en';
// $currentLang is the language I'll use to show the contents
$currentLang = $defaultLang;
$uri = ltrim(rawurldecode($uri), '/');
$parts = explode('/', $uri);
if( ! empty($parts) && in_array(strtolower($parts[0]), $languages)) {
$currentLang = array_shift($parts);
}
$routableUri = implode('/', $parts);
return $routableUri;
}
Check in Url: localhost/cms/ and Output Is: cms/ and not work true.
In action I need to check My url, if not detect language short name ie: en default language = en and then put in session or cookie But if detect language short name ie: fr es de set session or cookie to this language.
How do can I fix my problem and check my url for language short name?!
