- /* Detect user's langage if we are in automatic mode. */
- if (strcmp ($cfg['lang'], 'auto') == 0)
- {
- if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE']))
- $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
- else
- $l = "en";
+function t_parse_accept_language() {
+ if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
+ return [];
+ }
+ // 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]);