init_gettext.php
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
* First find the browser encoding and try to create a valid locale
* from one of the supported browser encodings. Start with the most
* preferred encoding.
* If no country code is found use the same as for language.
* !!! FIXME: Is this code correct for IE too??? !!!
*/
$langs = explode (",", $_SERVER[HTTP_ACCEPT_LANGUAGE]);
foreach ($langs as $lang)
{
preg_match("/^([a-z]{2})-*([a-z|A-Z]{2})*(;q=* *)*([0-9].[0-9])*$/",
$lang, $lng_pref);
$la = $lng_pref[1];
$co = strtoupper ($lng_pref[2]);
$pr = ($lng_pref[4] == "") ? 1.0 : $lng_pref[4];
if ($co == "")
{
switch(true) {
case $la === "en":
$co = "GB";
break;
case $la === "ja":
$co = "JP";
break;
default:
/* if not set most of the time i assume co = strtoupper (la) */
$co = strtoupper ($la);
}
}
if ($co != "US")
$la_specs[$la."_".$co]=$pr;
else
$la_specs["POSIX"]=$pr;
}
array_multisort ($la_specs, SORT_DESC, SORT_NUMERIC);
/*
* Set locale and initialize gettext catalogs
*/
foreach ($la_specs as $key => $value)
if ("" != ($locale=setlocale (LC_MESSAGES, $key))) break;
setlocale (LC_TIME, $locale);
bindtextdomain ("messages", OEDL_DIR . 'locale');
bind_textdomain_codeset ("messages", "UTF-8");
textdomain ("messages");
?>