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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
<?php
/**
* PHPPgAdmin v6.0.0-RC7
*/
namespace PHPPgAdmin;
/**
* Class for translations.
*/
class Translations
{
// List of language files, and encoded language name.
public $appLangFiles = [
'afrikaans' => 'Afrikaans',
'arabic' => 'عربي',
'catalan' => 'Català',
'chinese-tr' => '繁體中文',
'chinese-sim' => '简体中文',
'chinese-utf8-zh_TW' => '正體中文(UTF-8)',
'chinese-utf8-zh_CN' => '简体中文(UTF-8)',
'czech' => 'Česky',
'danish' => 'Danish',
'dutch' => 'Nederlands',
'english' => 'English',
'french' => 'Français',
'galician' => 'Galego',
'german' => 'Deutsch',
'greek' => 'Ελληνικά',
'hebrew' => 'Hebrew',
'hungarian' => 'Magyar',
'italian' => 'Italiano',
'japanese' => '日本語',
'lithuanian' => 'Lietuvių',
'mongol' => 'Mongolian',
'polish' => 'Polski',
'portuguese-br' => 'Português-Brasileiro',
'portuguese-pt' => 'Português',
'romanian' => 'Română',
'russian-utf8' => 'Русский (UTF-8)',
'russian' => 'Русский',
'slovak' => 'Slovensky',
'spanish' => 'Español',
'swedish' => 'Svenska',
'turkish' => 'Türkçe',
'ukrainian' => 'Укра╖нська',
];
public $appClasses = [
'afrikaans' => 'Afrikaans',
'arabic' => 'Arabic',
'catalan' => 'Catalan',
'chinese-tr' => 'ChineseTr',
'chinese-sim' => 'ChineseSim',
'chinese-utf8-zh_TW' => 'ChineseUtf8ZhTw',
'chinese-utf8-zh_CN' => 'ChineseUtf8ZhCn',
'czech' => 'Czech',
'danish' => 'Danish',
'dutch' => 'Dutch',
'english' => 'English',
'french' => 'French',
'galician' => 'Galician',
'german' => 'German',
'greek' => 'Greek',
'hebrew' => 'Hebrew',
'hungarian' => 'Hungarian',
'italian' => 'Italian',
'japanese' => 'Japanese',
'lithuanian' => 'Lithuanian',
'mongol' => 'Mongol',
'polish' => 'Polish',
'portuguese-br' => 'PortugueseBr',
'portuguese-pt' => 'PortuguesePt',
'romanian' => 'Romanian',
'russian-utf8' => 'RussianUtf8',
'russian' => 'Russian',
'slovak' => 'Slovak',
'spanish' => 'Spanish',
'swedish' => 'Swedish',
'turkish' => 'Turkish',
'ukrainian' => 'Ukrainian',
];
private $_language;
/**
* ISO639 language code to language file mapping.
* See http://www.w3.org/WAI/ER/IG/ert/iso639.htm for language codes
* If it's available 'language-country', but not general
* 'language' translation (eg. 'portuguese-br', but not 'portuguese')
* specify both 'la' => 'language-country' and 'la-co' => 'language-country'.
*/
public $availableLanguages = [
'af' => 'afrikaans',
'ar' => 'arabic',
'ca' => 'catalan',
'zh' => 'chinese-tr',
'zh-cn' => 'chinese-sim',
'utf8-zh-cn' => 'chinese-utf8-zh_TW',
'utf8-zh-tw' => 'chinese-utf8-zh_CN',
'cs' => 'czech',
'da' => 'danish',
'nl' => 'dutch',
'en' => 'english',
'fr' => 'french',
'gl' => 'galician',
'de' => 'german',
'el' => 'greek',
'he' => 'hebrew',
'hu' => 'hungarian',
'it' => 'italian',
'ja' => 'japanese',
'lt' => 'lithuanian',
'mn' => 'mongol',
'pl' => 'polish',
'pt-br' => 'portuguese-br',
'pt' => 'portuguese-pt',
'ro' => 'romanian',
'ru' => 'russian',
'ru' => 'russian',
'sk' => 'slovak',
'es' => 'spanish',
'sv' => 'swedish',
'tr' => 'turkish',
'uk' => 'ukrainian',
];
public $languages_iso_code = [
'afrikaans' => 'af',
'arabic' => 'ar',
'catalan' => 'ca',
'chinese-tr' => 'zh-CN',
'chinese-sim' => 'zh-CN',
'chinese-utf8-zh_TW' => 'zh-TW',
'chinese-utf8-zh_CN' => 'zh-CN',
'czech' => 'cs',
'danish' => 'da',
'dutch' => 'nl',
'english' => 'en',
'french' => 'fr',
'galician' => 'gl',
'german' => 'de',
'greek' => 'el',
'hebrew' => 'he',
'hungarian' => 'hu',
'italian' => 'it',
'japanese' => 'ja',
'lithuanian' => 'lt',
'mongol' => 'mn',
'polish' => 'pl',
'portuguese-br' => 'pt-BR',
'portuguese-pt' => 'pt',
'romanian' => 'ro',
'russian' => 'ru',
'russian' => 'ru',
'slovak' => 'sk',
'spanish' => 'es',
'swedish' => 'sv',
'turkish' => 'tr',
'ukrainian' => 'uk',
];
public function __construct($container)
{
$appLangFiles = $this->appLangFiles;
$appClasses = $this->appClasses;
$_language = $this->_language;
$conf = $container->conf;
$languages_iso_code = $this->languages_iso_code;
if (!isset($conf['default_lang'])) {
$conf['default_lang'] = 'english';
}
// 1. Check for the language from a request var
if (isset($_REQUEST['language'], $appLangFiles[$_REQUEST['language']])) {
/* save the selected language in cookie for a year */
setcookie('webdbLanguage', $_REQUEST['language'], time() + 31536000);
$_language = $_REQUEST['language'];
} elseif (!isset($_language) && isset($_SESSION['webdbLanguage'], $appLangFiles[$_SESSION['webdbLanguage']])) {
// 2. Check for language in $_SESSION superglobal
$_language = $_SESSION['webdbLanguage'];
} elseif (!isset($_language) && isset($_COOKIE['webdbLanguage'], $appLangFiles[$_COOKIE['webdbLanguage']])) {
// 3. Check for language in $_COOKIE superglobal
$_language = $_COOKIE['webdbLanguage'];
} elseif (!isset($_language) && $conf['default_lang'] == 'auto' && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
// 4. Check for acceptable languages in$_SERVER['HTTP_ACCEPT_LANGUAGE']
// extract acceptable language tags
// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4)
$_language = $this->_pregMatchAcceptLanguage();
} elseif (!isset($_language) && $conf['default_lang'] != 'auto' && isset($appLangFiles[$conf['default_lang']])) {
// 5. Otherwise resort to the default set in the config file
$_language = $conf['default_lang'];
} else {
// 6. Otherwise, default to english.
$_language = 'english';
}
$_type = '\PHPPgAdmin\Translations\\'.$appClasses[$_language];
$langClass = new $_type();
$_SESSION['webdbLanguage'] = $_language;
if (array_key_exists($_language, $languages_iso_code)) {
$_isolang = $languages_iso_code[$_language];
} else {
$_isolang = 'en';
}
$_SESSION['isolang'] = $_isolang;
$container->offsetSet('appLangFiles', $appLangFiles);
$container->offsetSet('language', $_language);
$container->offsetSet('isolang', $_isolang);
$this->lang = $langClass->getLang();
$this->lang['isolang'] = $_isolang;
}
/**
* Check for acceptable languages in$_SERVER['HTTP_ACCEPT_LANGUAGE']
* extract acceptable language tags.
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 Accept Language
*
* @return null|string candidate language or null if there's nonne
*/
private function _pregMatchAcceptLanguage()
{
$_language = null;
$_acceptLang = [];
preg_match_all(
'/\s*([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;q=([01](?:.[0-9]{0,3})?))?\s*(?:,|$)/',
strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']),
$_m,
PREG_SET_ORDER
);
foreach ($_m as $_l) {
// $_l[1] = language tag, [2] = quality
if (!isset($_l[2])) {
$_l[2] = 1;
}
// Default quality to 1
if ($_l[2] > 0 && $_l[2] <= 1 && isset($this->availableLanguages[$_l[1]])) {
// Build up array of (quality => language_file)
$_acceptLang[$_l[2]] = $this->availableLanguages[$_l[1]];
}
}
unset($_m, $_l);
if (!empty($_acceptLang)) {
// Sort acceptable languages by quality
krsort($_acceptLang, SORT_NUMERIC);
$_language = reset($_acceptLang);
unset($_acceptLang);
}
return $_language;
}
}
|