SCRIPT TO CHANGE LANGUAGE ON REALTIME BUT ON JAVASCRIPT WITHOUT USING A SERVER 2007/11/01
This Script do the work using layers on JavaScript was tested on Mozilla Firefox of course and I don't know if it works with MSIE, so you tell me, you should include 2 files on your page, gus_language_selector.js as script tag and gus_language_selector.css as style file containing all the languages you are going to support, by default it includes only 'es' and 'en' so, you just need to add more lang codes. The autodetect_language(); function can be called any time, like at end of the page or onload event of the body.
SCRIPT PARA CAMBIAR EN TIEMPO REAL EL IDIOMA EN JAVASCRIPT SIN USAR UN SERVIDOR 2007/11/01
Este script hace el trabajo con capas en JavaScript, fue probado con Mozilla Firefox por supuesto y no tengo idea si anda con MSIE, así que ya me dirás, debes incluir 2 archivos, gus_language_selector.js en una etiqueta de script y gus_language_selector.css como estilo conteniendo todos los códigos de idiomas que deseas soportar, por defecto están 'es' y 'en' así que sólo necesitas añadir más códigos de idioma. La función autodetect_language(); la puedes llamar en cualquier momento, como al final de la página o en el evento onload de body.
Si puedes ver esta página se traduce sola en tiempo real
As you can see this page is auto translated in real time
O puedes Elegir
Esta versión de Javascript Language Selector puede ser usada por cualquiera que no tenga
intenciones de hacer dinero directamente, esto significa que no puedes vender el código como tal
puedes usarlo en tu web o tu proyecto php, o ponerlo en el CD de una recvista, si realmente
haces negocios con tu proyecto y mi código, considera compartirlo :P.
Si quieres incluir este selector en algun editor web, no remuevas esta leyenda por favor.
La última versión la puedes encontrar en
Or you can Choose
This version of JavaScript Language Selector can be used by anyone who is not intented
to do profit directly with this code, it means you can not sale the code as is,
you can use it ont your web or php project, or put in a CD Magazine, if you really
do profit with your project and my code consider sharing them :P.
If you want to include the selector in some web editor, do not remove this legend.
The lastest version can be found at
//JAVASCRIPT LANGUAGE SELECTOR BY madgus@gmail.com
/* This version of JavaScript Language Selector can be used by anyone who is not intented
to do profit directly with this code, it means you can not sale the code as is,
you can use it ont your web or php project, or put in a CD Magazine, if you really
do profit with your project and my code consider sharing them :P.
If you want to include the selector in some web editor, do not remove this legend.
The lastest version can be found at
http://www.compunauta.com/forums/linux/programacion/java/gus_language_selector.html
This is Open and Free Software, madgus@gmail.com, gustavo@compunauta.com
bugfix - feb bad days.
*/
//DEFINE FIRST ALL STYLES STARTING WITH lang. LIKE lang.es lang.en AND SO ON
var idiomas = new Array();
idiomas[0]='es';
idiomas[1]='en';
//idiomas[2]='fr';
//idiomas[3]='gr';
DEFAULT_LANGUAGE='en';
function autodetect_language(){
language=(navigator["language"])?navigator["language"]:navigator["userLanguage"];
language=language.toLowerCase();
language=language.substring(0,2);
auto=false;
for(i=0; i<idiomas.length ; i++){
if(idiomas[i] == language){auto=true;}
}
if (auto==false){
set_lang(DEFAULT_LANGUAGE);
}else{
set_lang(language);
}
}
function set_lang(idioma){
for (m=0; m < idiomas.length; m++){
if (idiomas[m] == idioma) {
unhide_class('lang.'+idiomas[m]);
}else{
hide_class('lang.'+idiomas[m]);
}
}
}
function hide_class(classname){
capas = document.getElementsByTagName('div');
for(var i = 0;i < capas.length ;i++){
var capa = capas.item(i);
for(var j = 0; j < capa.attributes.length; j++){
if(capa.attributes.item(j).nodeName == 'class'){
if(capa.attributes.item(j).nodeValue == classname){
capa.style.display = 'none';
}
}
}
}
}
function unhide_class(classname){
capas = document.getElementsByTagName('div');
for(var i = 0;i < capas.length ;i++){
var capa = capas.item(i);
for(var j = 0; j < capa.attributes.length; j++){
if(capa.attributes.item(j).nodeName == 'class'){
if(capa.attributes.item(j).nodeValue == classname){
capa.style.display = 'block';
}
}
}
}
}
gus_language_selector.js
PUEDE HACER SUGERENCIAS, COMENTARIOS O CRÍTICAS POR MEDIO DE ESTE FORMULARIO