Saluton [English version follows],
Mi volas scii kial la adreso
http://www.wikipedia.org kondukas automate
al la adreso
http://en.wikipedia.org... Chu Wikipedia estas angla
projekto kun tradukoj, au chu ghi vere estas internacia? Oni povas uzi
tiun PHP programon por solvi tiun problemon :
function handle_http_accept_language() {
$knownlangs = array( "eo", "fr", "en" ); # Etc
$lang = "eo"; # Default
$lastquality = 0.0;
# Note HTTP reference RFC 2616 -
#
ftp://ftp.isi.edu/in-notes/rfc2616.txt
$langtag = '((?:[a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*)';
$qvalue ='(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3}))';
$eachbit = '^' . $langtag . '(?:;q=' . $qvalue .
')?(?:,\s*)?(.*)$';
$alh = trim( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
while(strlen($alh)) {
if( preg_match( "/$eachbit/", $alh, $m ) ) {
$tag = $m[1];
$quality = $m[2];
if(strlen($quality) == 0) $quality = 1;
$alh = $m[3];
#echo "language '$tag' quality '$quality'\n";
if(in_array($tag, $knownlangs) and $quality > $lastquality) {
$lang = $tag;
$lastquality = $quality;
}
} else {
break;
}
}
return $lang;
}
Mi ne subskribis al la listo, char estas mia nura propono. :-)
Dankon,
Grégoire
===========
Hello,
I want to know why the address
http://www.wikipedia.org redirects
automatically to
http://en.wikipedia.org... Is Wikipedia an english
project with translations, or is it a real international project? We can
use this PHP program to solve this problem :
function handle_http_accept_language() {
$knownlangs = array( "eo", "fr", "en" ); # Etc
$lang = "eo"; # Default
$lastquality = 0.0;
# Note HTTP reference RFC 2616 -
#
ftp://ftp.isi.edu/in-notes/rfc2616.txt
$langtag = '((?:[a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*)';
$qvalue ='(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3}))';
$eachbit = '^' . $langtag . '(?:;q=' . $qvalue .
')?(?:,\s*)?(.*)$';
$alh = trim( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
while(strlen($alh)) {
if( preg_match( "/$eachbit/", $alh, $m ) ) {
$tag = $m[1];
$quality = $m[2];
if(strlen($quality) == 0) $quality = 1;
$alh = $m[3];
#echo "language '$tag' quality '$quality'\n";
if(in_array($tag, $knownlangs) and $quality > $lastquality) {
$lang = $tag;
$lastquality = $quality;
}
} else {
break;
}
}
return $lang;
}
I did not subscribe to the list, because this is my only proposition.
Thank you,
Grégoire