| 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 |
"en" => true,
|
| 13 |
"en_US" => true, "en_GB" => true,
|
| 14 |
"en_AU" => true, "en_BW" => true,
|
| 15 |
"en_CA" => true, "en_DK" => true,
|
| 16 |
"en_HK" => true, "en_IE" => true,
|
| 17 |
"en_IN" => true, "en_NZ" => true,
|
| 18 |
"en_PH" => true, "en_SG" => true,
|
| 19 |
"en_ZA" => true, "en_ZW" => true,
|
| 20 |
"it" => true,
|
| 21 |
"it_IT" => true, "it_CH" => true,
|
| 22 |
);
|
| 23 |
|
| 24 |
$i = 0;
|
| 25 |
foreach ($lang_arr as $lang_code) {
|
| 26 |
$tmp[] = explode(";", $lang_code);
|
| 27 |
|
| 28 |
// let's use the aa_BB format
|
| 29 |
preg_match("/([a-zA-Z]+)-([a-zA-Z]+)/", $tmp[$i][0], $matches);
|
| 30 |
$tmp[$i][0] = ($matches) ? strtolower($matches[1]) . "_" . strtoupper($matches[2]) : $tmp[$i][0];
|
| 31 |
$langs[str_replace("q=", "", $tmp[$i][1])] = $tmp[$i][0];
|
| 32 |
$i++;
|
| 33 |
}
|
| 34 |
|
| 35 |
// let's sort them by priority, highest first
|
| 36 |
krsort($langs);
|
| 37 |
|
| 38 |
$locale = "en_US";
|
| 39 |
$priority = "0.0";
|
| 40 |
|
| 41 |
foreach ($langs as $index => $language) {
|
| 42 |
var_dump($language);
|
| 43 |
if ($available[$language]) {
|
| 44 |
switch ($language) {
|
| 45 |
case "it":
|
| 46 |
case "it_IT":
|
| 47 |
case "it_CH":
|
| 48 |
$locale = "it_IT"; break;
|
| 49 |
case "en":
|
| 50 |
case "en_US":
|
| 51 |
case "en_GB":
|
| 52 |
case "en_AU":
|
| 53 |
case "en_BW":
|
| 54 |
case "en_CA":
|
| 55 |
case "en_DK":
|
| 56 |
case "en_HK":
|
| 57 |
case "en_IE":
|
| 58 |
case "en_IN":
|
| 59 |
case "en_NZ":
|
| 60 |
case "en_PH":
|
| 61 |
case "en_SG":
|
| 62 |
case "en_ZA":
|
| 63 |
case "en_ZW":
|
| 64 |
default:
|
| 65 |
$locale = "en_US"; break;
|
| 66 |
}
|
| 67 |
$priority = $index;
|
| 68 |
break;
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
var_dump($locale);
|
| 73 |
|
| 74 |
if ($priority < "0.8") {
|
| 75 |
$show_locale_warning = true;
|
| 76 |
}
|
| 77 |
|
| 78 |
putenv("LC_ALL=$locale.UTF-8");
|
| 79 |
putenv("LANG=$locale.UTF-8");
|
| 80 |
putenv("LANGUAGE=$locale.UTF-8");
|
| 81 |
setlocale(LC_ALL, "$locale.UTF-8");
|
| 82 |
$domain = "messages";
|
| 83 |
//bindtextdomain("messages", $locales_dir);
|
| 84 |
bindtextdomain($domain, "./locale");
|
| 85 |
textdomain($domain);
|
| 86 |
|
| 87 |
?>
|