Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/03/2011, 09:02
amanitacreaciones
 
Fecha de Ingreso: octubre-2010
Ubicación: Aachen
Mensajes: 160
Antigüedad: 15 años, 11 meses
Puntos: 22
[aporte] Pagina web multi idioma por $_GET

Hace un tiempo que tengo un currículum online, pero hace un par de dias decidí hacerlo multi idioma.

Buscando encontré varios métodos (sesiones,...), pero ninguno me convenció 100% así que pensé en hacerlo desde cero.

Es una web muy simple, pero espero que pueda ayudar a algún principiante (como yo).


Index.php
Código PHP:
<?php
  
include ('traducciones.php');
        include (
'lenguas.php');
        include (
'menu.php');
        include (
'body.php');
        include (
'footer.php');
?>
Lenguas.php (para poder cambiar de idioma)
Código PHP:
<?php
if (isset($_GET['menu'])){
echo 
"<div id='idiomas'>
    <div id='idioma1'><a href='index.php?lang=es&menu="
.$_GET['menu']."'><img src='objetos/trans.png' border='0'/></a></div> 
    <div id='idioma2'><a href='index.php?lang=en&menu="
.$_GET['menu']."'><img src='objetos/trans.png' border='0'/></a></div> 
</div> <br>"
;
} else {
echo 
"<div id='idiomas'>
    <div id='idioma1'><a href='index.php?lang=es&menu=1'><img src='objetos/trans.png' border='0'/></a></div> 
    <div id='idioma2'><a href='index.php?lang=en&menu=1'><img src='objetos/trans.png' border='0'/></a></div> 
</div> <br>"
;
}
?>
Menu.php (sin menú pocas páginas vas a mostrar)

Código PHP:
<?php
$boton1
= 'boton1_'.$idioma;
$boton2= 'boton2_'.$idioma;
$boton3= 'boton3_'.$idioma;
$boton4= 'boton4_'.$idioma;
$boton5= 'boton5_'.$idioma;
$boton6= 'boton6_'.$idioma;
$boton7= 'boton7_'.$idioma;
$boton8= 'boton8_'.$idioma;



echo 
"<ul id='menu'>
    <li><a href='index.php?lang="
.$idioma."&menu=1'>".${$boton1}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=2'>".${$boton2}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=3'>".${$boton3}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=4'>".${$boton4}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=5'>".${$boton5}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=6'>".${$boton6}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=7'>".${$boton7}."</a></li>
    <li><a href='index.php?lang="
.$idioma."&menu=8'>".${$boton8}."</a></li>
</ul>"
;

?>
Body.php (donde se mostraran las páginas)
Código PHP:
<?php
    
if ($_GET['menu']==1 || !isset($_GET['menu'])){

echo 
" <div id='fondo1'> </div>     ";
    
    } else {
    echo 
" 
    <div id='fondo"
.$_GET['menu']."'>     </div>";
    
    }
    
    
    
    if (
$_GET['menu']==1 || !isset($_GET['menu'])) {
        
$texto= 'texto1_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==2) {
        
$texto= 'texto2_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==3) {
        
$texto= 'texto3_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==4) {
        
$texto= 'texto4_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==5) {
        
$texto= 'texto5_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==6) {
        
$texto= 'texto6_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==7) {
        
$texto= 'texto7_'.$idioma;
        echo ${
$texto};
    } else if (
$_GET['menu']==8) {
        
$texto= 'texto8_'.$idioma;
        echo ${
$texto};

} 
 

?>
Footer.php

Código PHP:
<?php
    $footer
= 'footer_'.$idioma;
    echo ${
$footer};
?>
Traducciones (aquí es donde debes escribir el contenido de la página y los botones en los diferentes idiomas, acepta entradas en html, pero hay que tener cuidado en no escribir "".)

Código PHP:
<?php
//Texto en castellano
//Inicio
$texto1_es = "Texto 1
"
;
$boton1_es = "Texto boton 1";

//Datos personales
$texto2_es = "Texto 2";
$boton2_es = "Texto boton 2";

//Estudios
$texto3_es = "Texto 3";
$boton3_es = "Texto boton 3";

//Trabajos
$texto4_es = "Texto boton 4";
$boton4_es = "Texto boton 4";

//Aptitudes
$texto5_es = "";
$boton5_es = "";

//Proyectos
$texto6_es = "";
$boton6_es = "";

//Futuro
$texto7_es = "";
$boton7_es = "";

//Contacto
$texto8_es = "";
$boton8_es = "";

//footer
$footer_es = "<div id='firma'>
    <p2>  </p2>
</div>"
;



//Texto en ingles
//Inicio
$texto1_en = "Texto 1 en ingles";
$boton1_en = "Boton 1";

//Datos personales
$texto2_en = "Texto 2 en ingles";
$boton2_en = "Boton 2";

//Estudios
$texto3_en = "Texto 3 en ingles";
$boton3_en = "Boton 3";

//Trabajos
$texto4_en = "Texto 4 en ingles";
$boton4_en = "Boton 4";

//Aptitudes
$texto5_en = "";
$boton5_en = "";

//Proyectos
$texto6_en = "";
$boton6_en = "";

//Futuro
$texto7_en = "";
$boton7_en = "";

//Contactos
$texto8_en = "";
$boton8_en = "";


//Footer
$footer_en = "<div id='firma'>
    <p2> <span>. .</span> </p2>
</div>"
;

?>
PS: como vereis está hecha para que por css podáis hacer que cada página tenga un div diferente y así poder poner diferente forma, color, fondo...

Última edición por GatorV; 15/03/2011 a las 09:19 Razón: quitar links