forked from openSUSE/old-landing-page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·39 lines (33 loc) · 1.08 KB
/
index.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
<?php
/**
* language switch
*
* redirects to the language version according to the browser language
*
* @author Andreas Demmer <mail@andreas-demmer>
*/
if (isset ($_POST['language']) && (bool)$_POST['language']) {
/* language was manually selected */
header ('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . $_POST['language'] . '/');
} else {
/* detect browser language */
$browserLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($browserLanguages as $key => $value) {
$value = strtolower ($value);
$value = str_replace ('_', '-', $value);
// search for i18n AND l10n
if (file_exists ($value)) {
header ('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . $value . '/');
exit;
}
// no i18n AND l10n found, try only i10n
preg_match ('/^[a-z]+/', $value, $matches);
if (is_array($matches) && isset($matches['0']) && file_exists ($matches['0'])) {
header ('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . $matches['0'] . '/');
exit;
}
}
/* fallback language */
header ('Location: http://' . $_SERVER['HTTP_HOST'] . '/en/');
}
?>