|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// Copyright (C) 2014-2016 Universitätsbibliothek Mannheim |
|
4
|
|
|
// See file LICENSE for license details. |
|
5
|
|
|
|
|
6
|
|
|
// Test whether the script was called directly (used for unit test). |
|
7
|
|
|
if (!isset($unittest)) { |
|
8
|
|
|
$unittest = array(); |
|
9
|
|
|
} |
|
10
|
|
|
$unittest[__FILE__] = (sizeof(get_included_files()) == 1); |
|
11
|
|
|
|
|
12
|
|
|
require_once('php-gettext/gettext.inc'); |
|
13
|
|
|
|
|
14
|
|
|
// The default translations are in locale/en_US.UTF-8/LC_MESSAGES/palma.mo. |
|
15
|
|
|
$locale = ''; |
|
16
|
|
|
if (isset($_REQUEST['lang'])) { |
|
17
|
|
|
// User requested language by URL parameter. |
|
18
|
|
|
$locale = $_REQUEST['lang']; |
|
19
|
|
|
$_SESSION['lang'] = $locale; |
|
20
|
|
|
} elseif (isset($_SESSION['lang'])) { |
|
21
|
|
|
// Get language from session data. |
|
22
|
|
|
$locale = $_SESSION['lang']; |
|
23
|
|
|
} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
24
|
|
|
// Get language from browser settings. |
|
25
|
|
|
$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); |
|
26
|
|
|
} |
|
27
|
|
|
switch (substr($locale, 0, 2)) { |
|
28
|
|
|
case 'al': |
|
29
|
|
|
// Albanian. |
|
30
|
|
|
$locale = 'sq_AL.UTF-8'; |
|
31
|
|
|
break; |
|
32
|
|
|
case 'ar': |
|
33
|
|
|
// Arabic. |
|
34
|
|
|
$locale = 'ar.UTF-8'; |
|
35
|
|
|
break; |
|
36
|
|
|
case 'de': |
|
37
|
|
|
// German. |
|
38
|
|
|
$locale = 'de_DE.UTF-8'; |
|
39
|
|
|
break; |
|
40
|
|
|
case 'el': |
|
41
|
|
|
// Greek. |
|
42
|
|
|
$locale = 'el_GR.UTF-8'; |
|
43
|
|
|
break; |
|
44
|
|
|
case 'en': |
|
45
|
|
|
// English. |
|
46
|
|
|
$locale = 'en_US.UTF-8'; |
|
47
|
|
|
break; |
|
48
|
|
|
case 'es': |
|
49
|
|
|
// Spanish. |
|
50
|
|
|
$locale = 'es_ES.UTF-8'; |
|
51
|
|
|
break; |
|
52
|
|
|
case 'fr': |
|
53
|
|
|
// French. |
|
54
|
|
|
$locale = 'fr_FR.UTF-8'; |
|
55
|
|
|
break; |
|
56
|
|
|
case 'hi': |
|
57
|
|
|
// Hindi. |
|
58
|
|
|
$locale = 'hi_IN.UTF-8'; |
|
59
|
|
|
break; |
|
60
|
|
|
case 'it': |
|
61
|
|
|
// Italian. |
|
62
|
|
|
$locale = 'it_IT.UTF-8'; |
|
63
|
|
|
break; |
|
64
|
|
|
case 'ja': |
|
65
|
|
|
// Japanese. |
|
66
|
|
|
$locale = 'ja.UTF-8'; |
|
67
|
|
|
break; |
|
68
|
|
|
case 'lv': |
|
69
|
|
|
// Latvian. |
|
70
|
|
|
$locale = 'lv_LV.UTF-8'; |
|
71
|
|
|
break; |
|
72
|
|
|
case 'ru': |
|
73
|
|
|
// Russian. |
|
74
|
|
|
$locale = 'ru_RU.UTF-8'; |
|
75
|
|
|
break; |
|
76
|
|
|
case 'ur': |
|
77
|
|
|
// Urdu. |
|
78
|
|
|
$locale = 'ur_PK.UTF-8'; |
|
79
|
|
|
break; |
|
80
|
|
|
case 'zh': |
|
81
|
|
|
// Chinese. |
|
82
|
|
|
$locale = 'zh_CN.UTF-8'; |
|
83
|
|
|
break; |
|
84
|
|
|
default: |
|
85
|
|
|
$locale = 'en_US.UTF-8'; |
|
86
|
|
|
break; |
|
87
|
|
|
} |
|
88
|
|
|
//~ error_log("setlocale $locale"); |
|
89
|
|
|
putenv("LANG=$locale"); |
|
90
|
|
|
_setlocale(LC_MESSAGES, $locale); |
|
|
|
|
|
|
91
|
|
|
_bindtextdomain('palma', 'locale'); |
|
|
|
|
|
|
92
|
|
|
_bind_textdomain_codeset('palma', 'UTF-8'); |
|
|
|
|
|
|
93
|
|
|
_textdomain('palma'); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
if ($unittest[__FILE__]) { |
|
96
|
|
|
|
|
97
|
|
|
function testlocale($locale = "") |
|
98
|
|
|
{ |
|
99
|
|
|
if ($locale != "") { |
|
100
|
|
|
_setlocale(LC_MESSAGES, $locale); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
error_log(sprintf('%-12s ', ($locale ? $locale : 'default') . ':') . addslashes(__('Screen section'))); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
// Run unit test. |
|
106
|
|
|
|
|
107
|
|
|
if (locale_emulation()) { |
|
|
|
|
|
|
108
|
|
|
print "locale '$locale' is not supported on your system, using custom gettext implementation.\n"; |
|
109
|
|
|
} else { |
|
110
|
|
|
print "locale '$locale' is supported on your system, using native gettext implementation.\n"; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
testlocale(); |
|
114
|
|
|
testlocale('sq_AL.UTF-8'); |
|
115
|
|
|
testlocale('ar.UTF-8'); |
|
116
|
|
|
testlocale('de_DE.UTF-8'); |
|
117
|
|
|
testlocale('el_GR.UTF-8'); |
|
118
|
|
|
testlocale('en_US.UTF-8'); |
|
119
|
|
|
testlocale('es_ES.UTF-8'); |
|
120
|
|
|
testlocale('fr_FR.UTF-8'); |
|
121
|
|
|
testlocale('hi_IN.UTF-8'); |
|
122
|
|
|
testlocale('it_IT.UTF-8'); |
|
123
|
|
|
testlocale('ja.UTF-8'); |
|
124
|
|
|
testlocale('lv_LV.UTF-8'); |
|
125
|
|
|
testlocale('ru_RU.UTF-8'); |
|
126
|
|
|
testlocale('ur_PK.UTF-8'); |
|
127
|
|
|
testlocale('zh_CN.UTF-8'); |
|
128
|
|
|
} |
|
129
|
|
|
|