| 1 |
<?php
|
| 2 |
// _SERVER["HTTP_ACCEPT_LANGUAGE"] it-it,it;q=0.8,en-gb;q=0.6,en-us;q=0.4,en;q=0.2
|
| 3 |
//$languages = "it-it,it;q=0.8,en-gb;q=0.6,en-us;q=0.4,en;q=0.2";
|
| 4 |
|
| 5 |
$languages = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
|
| 6 |
$lang_arr = explode(",", $languages);
|
| 7 |
$lang_arr[0] .= ";q=1.0";
|
| 8 |
|
| 9 |
$locales_dir = "/srv/alioth.debian.org/chroot/home/groups/debian-med/htdocs/locale/";
|
| 10 |
|
| 11 |
$available = array();
|
| 12 |
$handle = opendir($locales_dir) or die("Cannot open $locales_dir.\n");
|
| 13 |
while ($file = readdir($handle)) {
|
| 14 |
clearstatcache();
|
| 15 |
if ($file != "." && $file != "..") {
|
| 16 |
if (is_dir($locales_dir.$file))
|
| 17 |
$available[] = $file;
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
$i = 0;
|
| 22 |
foreach ($lang_arr as $lang_code) {
|
| 23 |
$tmp[] = explode(";", $lang_code);
|
| 24 |
|
| 25 |
// let's use the aa_BB format
|
| 26 |
preg_match("/([a-zA-Z]+)-([a-zA-Z]+)/", $tmp[$i][0], $matches);
|
| 27 |
$tmp[$i][0] = ($matches) ? strtolower($matches[1]) . "_" . strtoupper($matches[2]) : $tmp[$i][0];
|
| 28 |
$langs[str_replace("q=", "", $tmp[$i][1])] = $tmp[$i][0];
|
| 29 |
$i++;
|
| 30 |
}
|
| 31 |
|
| 32 |
// let's sort them by priority, highest first
|
| 33 |
krsort($langs);
|
| 34 |
|
| 35 |
$locale = "en_US";
|
| 36 |
$priority = "1.0";
|
| 37 |
|
| 38 |
foreach ($langs as $index => $language) {
|
| 39 |
// preg_match("/([a-z]+)_[A-Z]+/", $language, $matches);
|
| 40 |
// $test = $matches[1];
|
| 41 |
if (in_array($language, $available)) {
|
| 42 |
$locale = $language;
|
| 43 |
$priority = $index;
|
| 44 |
break;
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
if ($priority < "0.8") {
|
| 49 |
$show_locale_warning = true;
|
| 50 |
}
|
| 51 |
|
| 52 |
putenv("LC_ALL=$locale");
|
| 53 |
setlocale(LC_ALL, $locale);
|
| 54 |
$domain = "messages";
|
| 55 |
//bindtextdomain("messages", $locales_dir);
|
| 56 |
bindtextdomain($domain, "../locale/");
|
| 57 |
textdomain($domain);
|
| 58 |
|
| 59 |
?>
|