Change site language

0

I have a problem in the languages of the site, it has 4 languages and when you click on the other languages there are times when it changes and most of the time it does not exchange, I do not know if the information is stored in the cache. It was not me who developed the site so it is a bit more complicated to spend here, if any information is missing tell me what I look for.

Here is the language mapping

<map name="MapIdioma">
            <area shape="rect" coords="0,2,19,19" href="index.php?idioma=portugues">
            <area shape="rect" coords="24,2,43,18" href="index.php?idioma=english">
            <area shape="rect" coords="46,2,66,19" href="index.php?idioma=espanol">
            <area shape="rect" coords="69,2,89,17" href="index.php?idioma=alemao">
</map>

And here are the sessions that begin

if ($_REQUEST['idioma'] == 'portugues')
{
    $_SESSION['idIdioma']   = '1';
    /*header ("Location: ".$_SERVER['HTTP_REFERER']);*/
    echo "<script>document.location='".$_SERVER['HTTP_REFERER']."'</script>";
    exit();
}

if ($_REQUEST['idioma'] == 'english')
{
    $_SESSION['idIdioma']   = '2';
    /*header ("Location: ".$_SERVER['HTTP_REFERER']);*/
    echo "<script>document.location='".$_SERVER['HTTP_REFERER']."'</script>";
    exit();
}

if ($_REQUEST['idioma'] == 'espanol')
{
    $_SESSION['idIdioma']   = '3';
    /*header ("Location: ".$_SERVER['HTTP_REFERER']);*/
    echo "<script>document.location='".$_SERVER['HTTP_REFERER']."'</script>";
    exit();
}

if ($_REQUEST['idioma'] == 'alemao')
{
    $_SESSION['idIdioma']   = '4';
    /*header ("Location: ".$_SERVER['HTTP_REFERER']);*/
    echo "<script>document.location='".$_SERVER['HTTP_REFERER']."'</script>";
    exit();
}

if (!session_is_registered('idIdioma'))
    $_SESSION['idIdioma'] = '1';

if ($_SESSION['idIdioma'] != '1' and $_SESSION['idIdioma'] != '2' and $_SESSION['idIdioma'] != '3' and $_SESSION['idIdioma'] != '4')
    $_SESSION['idIdioma'] = '1';

if ($_SESSION['idIdioma'] == '1')
    include 'idioma.portugues.php';

if ($_SESSION['idIdioma'] == '2')
    include 'idioma.ingles.php';

if ($_SESSION['idIdioma'] == '3')
    include 'idioma.espanhol.php';

if ($_SESSION['idIdioma'] == '4')
    include 'idioma.alemao.php';
?>
    
asked by anonymous 29.07.2014 / 15:00

1 answer

2

I could not identify the problem, it might be something out of the scope of the script that passed us, however, I did get the freedom to rewrite your script.

link

$arrayIdiomas = array('portugues' => 'idioma.portugues.php', 'english' =>    'idioma.ingles.php', 'espanol' => 'idioma.espanhol.php', 'alemao' => 'idioma.alemao.php');

// Definindo o idioma padrão
if(!isset($_SESSION['idIdioma'])){
   $_SESSION['idIdioma'] = 'portugues';
}


 if(isset($_REQUEST['idioma'])){
 // o idioma seleciona existe?
  if(array_key_exists($_REQUEST['idioma'], $arrayIdiomas)){
    $_SESSION['idIdioma'] = $_REQUEST['idioma']; // seta o idioma selecionado
    echo "<script>document.location=$_SERVER['HTTP_REFERER']</script>"; // refresh na página
    exit();
 }
}
else{
 // idioma definido na sessão é valido?
 if(array_key_exists($_SESSION['idIdioma'], $arrayIdiomas)){
    include $arrayIdiomas [$_SESSION['idIdioma']]; // inclue o arquivo.
 }
}

I did not test, but I believe it is working, in this way your code will be more readable.

    
29.07.2014 / 15:40