- else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- return substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
- } else {
- return "en";
+ // Example: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5
+ $langs = [];
+ $cols = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ foreach ($cols as $i => $semicols) {
+ $lang = explode(';', $semicols);
+ if (count($lang) === 0) {
+ continue;
+ }
+ array_push($langs, $lang[0]);