initLocale.php
1.3 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
54
55
56
57
58
59
60
61
62
<?php
exec ('locale -a | sort -u', $locales);
$locale = 'C';
/*
* 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.
*/
$langs = explode (",", $_SERVER[HTTP_ACCEPT_LANGUAGE]);
foreach ($langs as $lang)
{
preg_match("/^([a-z]{2})(-([a-zA-Z]{2})){0,1}(;q=([0-9].[0-9])){0,1}$/",
$lang, $lng_pref);
$la = $lng_pref[1];
if (isset ($lng_pref[3]) && $lng_pref[3] !== "")
$co = '_' . strtoupper ($lng_pref[3]);
else
$co = '';
if (isset ($lng_pref[5]) && $lng_pref[5] !== "")
$pr = $lng_pref[5];
else
$pr = 1.0;
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)
{
foreach ($locales as $l)
{
if (isset ($key) && "" !== $key && strpos ($l, $key) !== FALSE)
{
$locale = $l;
break;
}
}
if ('C' !== $locale) break;
}
$l = setlocale (LC_MESSAGES, $locale);
if ($l !== $locale)
{
$locale = 'C';
setlocale (LC_MESSAGES, $locale);
}
setlocale (LC_TIME, $locale);
bindtextdomain ("bilder", LOCALEDIR);
bind_textdomain_codeset ("bilder", "UTF-8");
textdomain ("bilder");
?>