Jump to content

Multilanguage problem solving with an arry?


Henk de Wit

Recommended Posts

I’m using a multilanguage script to change from lanquage.

Now I’m having troubles to change from a language when I’m at the default language (English)

 

The site looks like:

 

example.com ( Main directory)

example.com/fr/

example.com/es/

 

When I’m at example.com/fr/blabla/index and I want to go to example.com/es/blabla/index it works fine.

 

But when I’m at example.com/blabla/index and I want to go to example.com/fr/blabla/index . I’m redirect to example.com/fr/index

 

I’m using:

 

    <?php

    function switchLanguage($lang) {

        $u = explode('/', $_SERVER['REQUEST_URI']);

        $u[1] = $lang;

        return implode('/', $u);

    }

 

    ?>

 

 

So it’s logic that I’m not redirect to the correct path because there is no directory /eng.

 

I was thinking is it possible to rewrite the url using a array?

Something like this:

 

 

    <?php

    function switchLanguage($lang)

    $array1 = array(' ', $_SERVER['REQUEST_URI']);

    $array2 = array('$lang', ' ');

    $newArray = array_combine($array1, $array2);

   

    foreach ($newArray as $key ) {

            echo "$key $value";

    }

 

    ?>

 

 

But how can I get the value in a url or where Am I going wrong.

 

To use a database or .ini and geoip caching is not an option

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.