I Have Url structure for multi language system like this:
for default language ie: en (not show/detect short language in url)
localhost/cms
localhost/cms/article/slug/etc...
And Another Language Like:
localhost/cms/fr
localhost/cms/fr/article/slug/etc...
My Idea:
- define a list of available languages for My app,
- define a default language I use when,
a. there is no language provided (
localhost/cms/users), b. the provided language is unknown (localhost/cms/fr/users). - in my code, get the current Language (ex:
en) and the routableURI, a URI without any language in it (ex: cms/users)
I have This code:
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;
}
My code output default language: (false Output)and not worked
check: localhost/cms/ Or localhost/cms/users/
Output is: cms/ Or cms/users/
Output for another language: (true Output)worked true
check: localhost/cms/fr/ Output is cms/fr/ Or localhost/cms/fr/users/Output is : cms/fr/users/
How do can i print my default language, without add/detect short language name in url like this?!
Check: localhost/cms Output Is:cms/en Or Check localhost/cms/users/ Output Is: cms/en/users/.