0

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:

  1. define a list of available languages for My app,
  2. 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).
  3. 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/.

2
  • maybe storing them in Cookie? Commented Jun 21, 2018 at 10:08
  • @BARNI: Belike, But In this Case I add To Route Class for routing url. Commented Jun 21, 2018 at 10:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.