Con questo script PHP si può scoprire la lingua dell’utente che visita la pagina web, con le utili conseguenze del caso.
// questo script reindirizza il navigatore a seconda della lingua function lixlpixel_get_env_var($Var) { if(empty($GLOBALS[$Var])) { $GLOBALS[$Var]=(!empty($GLOBALS['_SERVER'][$Var]))? $GLOBALS['_SERVER'][$Var]: (!empty($GLOBALS['HTTP_SERVER_VARS'][$Var]))? $GLOBALS['HTTP_SERVER_VARS'][$Var]:''; } } function lixlpixel_detect_lang() { // Detect HTTP_ACCEPT_LANGUAGE & HTTP_USER_AGENT. lixlpixel_get_env_var('HTTP_ACCEPT_LANGUAGE'); lixlpixel_get_env_var('HTTP_USER_AGENT'); $_AL=strtolower($GLOBALS['HTTP_ACCEPT_LANGUAGE']); $_UA=strtolower($GLOBALS['HTTP_USER_AGENT']); // Try to detect Primary language if several languages are accepted. foreach($GLOBALS['_LANG'] as $K) { if(strpos($_AL, $K)===0) return $K; } // Try to detect any language if not yet detected. foreach($GLOBALS['_LANG'] as $K) { if(strpos($_AL, $K)!==false) return $K; } foreach($GLOBALS['_LANG'] as $K) { if(preg_match("/[\[\( ]{$K}[;,_\-\)]/",$_UA)) return $K; } // Return default language if language is not yet detected. return $GLOBALS['_DLANG']; } // definizione lingua di default $GLOBALS['_DLANG']='en'; // definizione delle variabili lingua // ATTENZIONE: decommentare quelle in uso $GLOBALS['_LANG'] = array( 'af', // afrikaans. 'ar', // arabic. 'bg', // bulgarian. 'ca', // catalan. 'cs', // czech. 'da', // danish. 'de', // german. 'el', // greek. 'en', // inglese 'es', // spanish. 'et', // estonian. 'fi', // finnish. 'fr', // french. 'gl', // galician. 'he', // hebrew. 'hi', // hindi. 'hr', // croatian. 'hu', // hungarian. 'id', // indonesian. 'it', // italiano 'ja', // japanese. 'ko', // korean. 'ka', // georgian. 'lt', // lithuanian. 'lv', // latvian. 'ms', // malay. 'nl', // dutch. 'no', // norwegian. 'pl', // polish. 'pt', // portuguese. 'ro', // romanian. 'ru', // russian. 'sk', // slovak. 'sl', // slovenian. 'sq', // albanian. 'sr', // serbian. 'sv', // swedish. 'th', // thai. 'tr', // turkish. 'uk', // ukrainian. 'zh' // chinese. ); // Redirect to the correct location. // header('location: index.htm?lang='.lixlpixel_detect_lang() ); // Example Implementation // echo 'The Language detected is: '.lixlpixel_detect_lang(); // For Demonstration // $i=lixlpixel_detect_lang(); // header('location: '.$i.'-frame.php' ); }Altri sono arrivati qui cercando:
php riconoscere lingua, lingua php.
< ?php define('WP_USE_THEMES', true); if (substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2) == "it") { require('./blog/wp-blog-header.php'); } else { require('./blog_en/wp-blog-header.php'); } ?>
Ciao io cerco un traduttore di lingue per il mio sito web, esiste una applicazione PTP… Chi mi puo aiutare…
Ciao tonypuma, io non lo so cosa sia un’applicazione PTP… Cos’è?
Ciao Doz !!!
Vorrei un traduttore a tendina per il mio sito web!!!
Esempio lo trovi nel mio sito http://www.pubbliptr.net/
Mi puoi aiutare?
Ciao tonypuma,
per avere un menu a tendina con traduttore per il tuo sito puoi inserire il traduttore di Google nel tuo sito, inserendo il codice seguente dove vuoi il menù:
<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'it',
includedLanguages: 'ar,bg,zh-TW,fr,el,en,it,nl,pt,ru,es,de,uk,hu'
}, 'google_translate_element');
}
</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Il codice l’ho preso da questo sito, dove c’è il menù a tendina per la traduzione in cima alla barra laterale.
PS: però me lo dici cos’è un’applicazione PTP??