-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
executable file
·41 lines (33 loc) · 1.13 KB
/
setup.php
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
<?
include "../conf/config.php";
$debug=0;
$version="1.0";
function getPreferredLanguage($availableLanguages, $default = 'en') {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$acceptedLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$langs = [];
foreach ($acceptedLanguages as $lang) {
$lang = explode(';', $lang);
$langs[] = $lang[0];
}
// Check each language against available languages
foreach ($langs as $lang) {
if (in_array($lang, $availableLanguages)) {
return $lang;
}
// Check the language without the region code
$langPrimary = substr($lang, 0, 2);
if (in_array($langPrimary, $availableLanguages)) {
return $langPrimary;
}
}
}
// Return default language if no match is found
return $default;
}
// List of available languages in your application
$availableLanguages = ['en', 'ca'];
// Detect the user's preferred language
$userPreferredLanguage = getPreferredLanguage($availableLanguages);
//$userPreferredLanguage="en";
?>